From 7c99b9182636a3829c6e82f0fcd4dfe3c2211647 Mon Sep 17 00:00:00 2001 From: Costa Tsaousis Date: Fri, 13 May 2016 03:37:52 +0300 Subject: [PATCH] fix for case sensitive HTTP headers and gzip detection --- src/registry.c | 2 +- src/web_client.c | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/registry.c b/src/registry.c index 932ee5af..4e88dc65 100644 --- a/src/registry.c +++ b/src/registry.c @@ -1651,7 +1651,7 @@ int registry_init(void) { registry.save_registry_every_entries = config_get_number("registry", "registry save db every new entries", 1000000); registry.persons_expiration = config_get_number("registry", "registry expire idle persons days", 365) * 86400; registry.registry_domain = config_get("registry", "registry domain", ""); - registry.registry_to_announce = config_get("registry", "registry to announce", "https://registry.my-netdata.io"); + registry.registry_to_announce = config_get("registry", "registry to announce", "//registry.my-netdata.io"); registry.hostname = config_get("registry", "registry hostname", config_get("global", "hostname", hostname)); registry.max_url_length = config_get_number("registry", "max URL length", 1024); diff --git a/src/web_client.c b/src/web_client.c index 5cba375d..05647a28 100644 --- a/src/web_client.c +++ b/src/web_client.c @@ -1185,14 +1185,6 @@ cleanup: static inline char *http_header_parse(struct web_client *w, char *s) { - static uint32_t connection_hash = 0, accept_encoding_hash = 0, origin_hash = 0; - - if(unlikely(connection_hash == 0)) { - connection_hash = simple_hash("Connection"); - accept_encoding_hash = simple_hash("Accept-Encoding"); - origin_hash = simple_hash("Origin"); - } - char *e = s; // find the : @@ -1201,7 +1193,6 @@ static inline char *http_header_parse(struct web_client *w, char *s) { // get the name *e = '\0'; - uint32_t hash = simple_hash(s); // find the value char *v, *ve; @@ -1217,17 +1208,20 @@ static inline char *http_header_parse(struct web_client *w, char *s) { // terminate the value *ve = '\0'; - if(hash == origin_hash && !strcmp(s, "Origin")) { + // fprintf(stderr, "HEADER: '%s' = '%s'\n", s, v); + + if(!strcasecmp(s, "Origin")) { strncpy(w->origin, v, ORIGIN_MAX); } - else if(hash == connection_hash && !strcmp(s, "Connection")) { + else if(!strcasecmp(s, "Connection")) { if(!strcasestr(v, "keep-alive")) w->keepalive = 1; } #ifdef NETDATA_WITH_ZLIB - else if(hash == accept_encoding_hash && !strcmp(s, "Accept-Encoding")) { - if(web_enable_gzip && !strcasestr(v, "gzip")) + else if(!strcasecmp(s, "Accept-Encoding")) { + if(web_enable_gzip && strcasestr(v, "gzip")) { w->enable_gzip = 1; + } } #endif /* NETDATA_WITH_ZLIB */ @@ -1675,7 +1669,7 @@ void web_client_process(struct web_client *w) { if(w->mode == WEB_CLIENT_MODE_OPTIONS) { buffer_strcat(w->response.header_output, "Access-Control-Allow-Methods: GET, OPTIONS\r\n" - "Access-Control-Allow-Headers: Accept, X-Requested-With, Content-Type, Cookie\r\n" + "Access-Control-Allow-Headers: accept, x-requested-with, origin, content-type, cookie\r\n" "Access-Control-Max-Age: 1209600\r\n" // 86400 * 14 ); } -- 2.39.2