mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-27 15:45:56 -05:00
[httpd] Reply to CORS preflight requests
This commit is contained in:
parent
c44f4310b7
commit
57945a592c
19
src/httpd.c
19
src/httpd.c
@ -1045,10 +1045,29 @@ serve_file(struct evhttp_request *req, char *uri)
|
||||
static void
|
||||
httpd_gen_cb(struct evhttp_request *req, void *arg)
|
||||
{
|
||||
struct evkeyvalq *input_headers;
|
||||
struct evkeyvalq *output_headers;
|
||||
const char *req_uri;
|
||||
char *uri;
|
||||
char *ptr;
|
||||
|
||||
// Did we get a CORS preflight request?
|
||||
input_headers = evhttp_request_get_input_headers(req);
|
||||
if (allow_origin && (evhttp_request_get_command(req) == EVHTTP_REQ_OPTIONS) && evhttp_find_header(input_headers, "Origin"))
|
||||
{
|
||||
output_headers = evhttp_request_get_output_headers(req);
|
||||
|
||||
evhttp_add_header(output_headers, "Access-Control-Allow-Origin", allow_origin);
|
||||
|
||||
// Allow only GET method and authorization header in cross origin requests
|
||||
evhttp_add_header(output_headers, "Access-Control-Allow-Method", "GET");
|
||||
evhttp_add_header(output_headers, "Access-Control-Allow-Headers", "authorization");
|
||||
|
||||
// In this case there is no reason to go through httpd_send_reply
|
||||
evhttp_send_reply(req, HTTP_OK, "OK", NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
req_uri = evhttp_request_get_uri(req);
|
||||
if (!req_uri)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user