@cryptotaxi247 / netdata-1 / commits / ca1466f08

more strict CORS implementation; saved a few bytes per chart refresh by moving not required CORS headers to OPTIONS requests only

Costa Tsaousis (ktsaou) committed Apr 23, 2016 at 03:24 UTC ca1466f087ae6bd05000e1bde54bb51018603add
1 file changed +10 -5
src/web_client.c
+10 -5
@@ -1428,11 +1428,8 @@ void web_client_process(struct web_client *w) {
1428 "HTTP/1.1 %d %s\r\n"
1429 "Connection: %s\r\n"
1430 "Server: NetData Embedded HTTP Server\r\n"
1431 - "Content-Type: %s\r\n"
1431 "Access-Control-Allow-Origin: *\r\n"
1433 - "Access-Control-Allow-Methods: GET, OPTIONS\r\n"
1434 - "Access-Control-Allow-Headers: accept, x-requested-with\r\n"
1435 - "Access-Control-Max-Age: 86400\r\n"
1432 + "Content-Type: %s\r\n"
1433 "Date: %s\r\n"
1434 , code, code_msg
1435 , w->keepalive?"keep-alive":"close"
@@ -1440,6 +1437,14 @@ void web_client_process(struct web_client *w) {
1437 , date
1438 );
1439
1440 + if(w->mode == WEB_CLIENT_MODE_OPTIONS) {
1441 + buffer_strcat(w->response.header_output,
1442 + "Access-Control-Allow-Methods: GET, OPTIONS\r\n"
1443 + "Access-Control-Allow-Headers: accept, x-requested-with\r\n"
1444 + "Access-Control-Max-Age: 1209600\r\n" // 86400 * 14
1445 + );
1446 + }
1447 +
1448 if(buffer_strlen(w->response.header))
1449 buffer_strcat(w->response.header_output, buffer_tostring(w->response.header));
1450
@@ -1449,7 +1454,7 @@ void web_client_process(struct web_client *w) {
1454 "Cache-Control: no-cache\r\n"
1455 , date);
1456 }
1452 - else {
1457 + else if(w->mode != WEB_CLIENT_MODE_OPTIONS) {
1458 char edate[100];
1459 time_t et = w->response.data->date + (86400 * 14);
1460 struct tm etmbuf, *etm = gmtime_r(&et, &etmbuf);