0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-10 22:18:54 +02:00

ircd::resource: Handle and generate an OPTIONS response.

fixes #65
This commit is contained in:
Jason Volk 2019-03-31 23:01:34 -07:00
parent 7434a06ec6
commit dab225113d
2 changed files with 55 additions and 11 deletions

View file

@ -223,9 +223,56 @@ ircd::resource::handle_options(client &client,
const request &request)
const
{
const http::headers headers
{
request.head.headers
};
const string_view &request_origin
{
headers["origin"]
};
const string_view &allow_origin
{
resource::response::access_control_allow_origin
};
const string_view &request_headers
{
headers["access-control-request-headers"]
};
const string_view &allow_headers
{
request_headers
};
const string_view &request_method
{
headers["access-control-request-method"]
};
char allow_methods_buf[48];
const string_view &allow_methods
{
method_list(allow_methods_buf, [&](const method &method)
{
return true;
})
};
const http::header response_headers[]
{
// ACAO sent further up stack
//{ "Access-Control-Allow-Origin", allow_origin },
{ "Access-Control-Allow-Methods", allow_methods },
{ "Access-Control-Allow-Headers", allow_headers },
};
return response
{
client, http::METHOD_NOT_ALLOWED
client, {}, {}, http::OK, response_headers
};
}
@ -1209,6 +1256,12 @@ ircd::resource::response::response(client &client,
pretty(rtime_buf, request_time, true)
};
const http::header headers_addl[]
{
{ "X-IRCd-Request-Timer", rtime },
{ "Access-Control-Allow-Origin", string_view(access_control_allow_origin) },
};
char head_buf[HEAD_BUF_SZ];
window_buffer head{head_buf};
http::response
@ -1218,10 +1271,7 @@ ircd::resource::response::response(client &client,
content_length,
content_type,
headers,
{
{ "Access-Control-Allow-Origin", string_view(access_control_allow_origin) },
{ "X-IRCd-Request-Timer", rtime },
},
headers_addl,
};
// Maximum size is realistically ok but ideally a small

View file

@ -59,12 +59,6 @@ root_post
root_resource, "POST", non_get_root
};
resource::method
root_options
{
root_resource, "OPTIONS", non_get_root
};
resource::method
root_delete
{