Merge branch 'cors'

master
Nicolas Favre-Felix 14 years ago
commit ab81fb8a42

@ -116,6 +116,22 @@ on_flash_request(struct evhttp_request *rq, void *ctx) {
evbuffer_free(body);
}
#ifdef _EVENT2_HTTP_H_
/* reply to OPTIONS HTTP verb */
static int
on_options(struct evhttp_request *rq) {
evhttp_add_header(rq->output_headers, "Content-Type", "text/html");
evhttp_add_header(rq->output_headers, "Allow", "GET,POST,OPTIONS");
/* Cross-Origin Resource Sharing, CORS. */
evhttp_add_header(rq->output_headers, "Access-Control-Allow-Origin", "*");
evhttp_send_reply(rq, 200, "OK", body);
return 1;
}
#endif
void
on_request(struct evhttp_request *rq, void *ctx) {
const char *uri = evhttp_request_uri(rq);
@ -142,6 +158,11 @@ on_request(struct evhttp_request *rq, void *ctx) {
EVBUFFER_LENGTH(rq->input_buffer));
break;
#ifdef _EVENT2_HTTP_H_
case EVHTTP_REQ_OPTIONS:
return on_options(rq);
#endif
default:
slog(s, WEBDIS_DEBUG, "405");
evhttp_send_reply(rq, 405, "Method Not Allowed", NULL);

Loading…
Cancel
Save