mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-04 08:54:39 +00:00
Support cors in upload_api() and update_api().
This commit is contained in:
@@ -521,7 +521,20 @@ upload_api_cb(evhtp_request_t *req, void *arg)
|
|||||||
int replace = 0;
|
int replace = 0;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (evhtp_request_get_method(req) == htp_method_OPTIONS) {
|
evhtp_headers_add_header (req->headers_out,
|
||||||
|
evhtp_header_new("Access-Control-Allow-Headers",
|
||||||
|
"x-requested-with, content-type, accept, origin, authorization", 1, 1));
|
||||||
|
evhtp_headers_add_header (req->headers_out,
|
||||||
|
evhtp_header_new("Access-Control-Allow-Methods",
|
||||||
|
"GET, POST, PUT, PATCH, DELETE, OPTIONS", 1, 1));
|
||||||
|
evhtp_headers_add_header (req->headers_out,
|
||||||
|
evhtp_header_new("Access-Control-Allow-Origin",
|
||||||
|
"*", 1, 1));
|
||||||
|
evhtp_headers_add_header (req->headers_out,
|
||||||
|
evhtp_header_new("Access-Control-Max-Age",
|
||||||
|
"86400", 1, 1));
|
||||||
|
|
||||||
|
if (evhtp_request_get_method(req) == htp_method_OPTIONS) {
|
||||||
/* If CORS preflight header, then create an empty body response (200 OK)
|
/* If CORS preflight header, then create an empty body response (200 OK)
|
||||||
* and return it.
|
* and return it.
|
||||||
*/
|
*/
|
||||||
@@ -1213,6 +1226,27 @@ update_api_cb(evhtp_request_t *req, void *arg)
|
|||||||
int error_code = ERROR_INTERNAL;
|
int error_code = ERROR_INTERNAL;
|
||||||
char *new_file_id = NULL;
|
char *new_file_id = NULL;
|
||||||
|
|
||||||
|
evhtp_headers_add_header (req->headers_out,
|
||||||
|
evhtp_header_new("Access-Control-Allow-Headers",
|
||||||
|
"x-requested-with, content-type, accept, origin, authorization", 1, 1));
|
||||||
|
evhtp_headers_add_header (req->headers_out,
|
||||||
|
evhtp_header_new("Access-Control-Allow-Methods",
|
||||||
|
"GET, POST, PUT, PATCH, DELETE, OPTIONS", 1, 1));
|
||||||
|
evhtp_headers_add_header (req->headers_out,
|
||||||
|
evhtp_header_new("Access-Control-Allow-Origin",
|
||||||
|
"*", 1, 1));
|
||||||
|
evhtp_headers_add_header (req->headers_out,
|
||||||
|
evhtp_header_new("Access-Control-Max-Age",
|
||||||
|
"86400", 1, 1));
|
||||||
|
|
||||||
|
if (evhtp_request_get_method(req) == htp_method_OPTIONS) {
|
||||||
|
/* If CORS preflight header, then create an empty body response (200 OK)
|
||||||
|
* and return it.
|
||||||
|
*/
|
||||||
|
send_success_reply (req);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!fsm || fsm->state == RECV_ERROR)
|
if (!fsm || fsm->state == RECV_ERROR)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user