Fixed CORS.

master
Nicolas Favre-Felix 14 years ago
parent e9dd8df871
commit c9eab0c275

@ -20,6 +20,10 @@ http_response_init(struct http_response *r, int code, const char *msg) {
r->msg = msg; r->msg = msg;
http_response_set_header(r, "Server", "Webdis"); http_response_set_header(r, "Server", "Webdis");
/* Cross-Origin Resource Sharing, CORS. */
http_response_set_header(r, "Allow", "GET,POST,PUT,OPTIONS");
http_response_set_header(r, "Access-Control-Allow-Origin", "*");
} }
@ -57,7 +61,7 @@ http_response_set_header(struct http_response *r, const char *k, const char *v)
memcpy(r->headers[pos].val, v, val_sz); memcpy(r->headers[pos].val, v, val_sz);
r->headers[pos].val_sz = val_sz; r->headers[pos].val_sz = val_sz;
if(!strcmp(k, "Transfer-Encoding") && !strcmp(v, "Chunked")) { if(!r->chunked && !strcmp(k, "Transfer-Encoding") && !strcmp(v, "Chunked")) {
r->chunked = 1; r->chunked = 1;
} }
} }
@ -216,12 +220,8 @@ http_send_options(struct http_client *c) {
http_response_set_connection_header(c, &resp); http_response_set_connection_header(c, &resp);
http_response_set_header(&resp, "Content-Type", "text/html"); http_response_set_header(&resp, "Content-Type", "text/html");
http_response_set_header(&resp, "Allow", "GET,POST,PUT,OPTIONS");
http_response_set_header(&resp, "Content-Length", "0"); http_response_set_header(&resp, "Content-Length", "0");
/* Cross-Origin Resource Sharing, CORS. */
http_response_set_header(&resp, "Access-Control-Allow-Origin", "*");
http_response_write(&resp, c->fd); http_response_write(&resp, c->fd);
http_client_reset(c); http_client_reset(c);
} }

@ -59,9 +59,9 @@ test_lrange() {
info info
test_ping test_ping
test_set # test_set
test_get # test_get
test_incr # test_incr
test_lpush # test_lpush
test_lrange 0 10 # test_lrange 0 10
test_lrange 0 100 # test_lrange 0 100

Loading…
Cancel
Save