mirror of
https://github.com/transmission/transmission
synced 2024-12-27 01:57:52 +00:00
Added primitive CORS header support (#1885)
* Copied over patch from github user fecristovao * Added nullptr check
This commit is contained in:
parent
fb39c4663c
commit
d11ccf113c
1 changed files with 17 additions and 0 deletions
|
@ -633,6 +633,21 @@ static void handle_request(struct evhttp_request* req, void* arg)
|
|||
return;
|
||||
}
|
||||
|
||||
evhttp_add_header(req->output_headers, "Access-Control-Allow-Origin", "*");
|
||||
|
||||
if (req->type == EVHTTP_REQ_OPTIONS)
|
||||
{
|
||||
char const* headers = evhttp_find_header(req->input_headers, "Access-Control-Request-Headers");
|
||||
if (headers != nullptr)
|
||||
{
|
||||
evhttp_add_header(req->output_headers, "Access-Control-Allow-Headers", headers);
|
||||
}
|
||||
|
||||
evhttp_add_header(req->output_headers, "Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
||||
send_simple_response(req, 200, "");
|
||||
return;
|
||||
}
|
||||
|
||||
auth = evhttp_find_header(req->input_headers, "Authorization");
|
||||
|
||||
if (auth != nullptr && evutil_ascii_strncasecmp(auth, "basic ", 6) == 0)
|
||||
|
@ -728,6 +743,7 @@ static void handle_request(struct evhttp_request* req, void* arg)
|
|||
TR_RPC_SESSION_ID_HEADER,
|
||||
sessionId);
|
||||
evhttp_add_header(req->output_headers, TR_RPC_SESSION_ID_HEADER, sessionId);
|
||||
evhttp_add_header(req->output_headers, "Access-Control-Expose-Headers", TR_RPC_SESSION_ID_HEADER);
|
||||
send_simple_response(req, 409, tmp);
|
||||
tr_free(tmp);
|
||||
}
|
||||
|
@ -799,6 +815,7 @@ static void startServer(void* vserver)
|
|||
}
|
||||
|
||||
struct evhttp* httpd = evhttp_new(server->session->event_base);
|
||||
evhttp_set_allowed_methods(httpd, EVHTTP_REQ_GET | EVHTTP_REQ_POST | EVHTTP_REQ_OPTIONS);
|
||||
|
||||
char const* address = tr_rpcGetBindAddress(server);
|
||||
|
||||
|
|
Loading…
Reference in a new issue