@cryptotaxi247 / netdata-1 / commits / 7c99b9182

fix for case sensitive HTTP headers and gzip detection

Costa Tsaousis committed May 13, 2016 at 03:37 UTC 7c99b9182636a3829c6e82f0fcd4dfe3c2211647
2 files changed +9 -15
src/registry.c
+1 -1
@@ -1651,7 +1651,7 @@ int registry_init(void) {
1651 registry.save_registry_every_entries = config_get_number("registry", "registry save db every new entries", 1000000);
1652 registry.persons_expiration = config_get_number("registry", "registry expire idle persons days", 365) * 86400;
1653 registry.registry_domain = config_get("registry", "registry domain", "");
1654 - registry.registry_to_announce = config_get("registry", "registry to announce", "https://registry.my-netdata.io");
1654 + registry.registry_to_announce = config_get("registry", "registry to announce", "//registry.my-netdata.io");
1655 registry.hostname = config_get("registry", "registry hostname", config_get("global", "hostname", hostname));
1656
1657 registry.max_url_length = config_get_number("registry", "max URL length", 1024);
src/web_client.c
+8 -14
@@ -1185,14 +1185,6 @@ cleanup:
1185
1186
1187 static inline char *http_header_parse(struct web_client *w, char *s) {
1188 - static uint32_t connection_hash = 0, accept_encoding_hash = 0, origin_hash = 0;
1189 -
1190 - if(unlikely(connection_hash == 0)) {
1191 - connection_hash = simple_hash("Connection");
1192 - accept_encoding_hash = simple_hash("Accept-Encoding");
1193 - origin_hash = simple_hash("Origin");
1194 - }
1195 -
1188 char *e = s;
1189
1190 // find the :
@@ -1201,7 +1193,6 @@ static inline char *http_header_parse(struct web_client *w, char *s) {
1193
1194 // get the name
1195 *e = '\0';
1204 - uint32_t hash = simple_hash(s);
1196
1197 // find the value
1198 char *v, *ve;
@@ -1217,17 +1208,20 @@ static inline char *http_header_parse(struct web_client *w, char *s) {
1208 // terminate the value
1209 *ve = '\0';
1210
1220 - if(hash == origin_hash && !strcmp(s, "Origin")) {
1211 + // fprintf(stderr, "HEADER: '%s' = '%s'\n", s, v);
1212 +
1213 + if(!strcasecmp(s, "Origin")) {
1214 strncpy(w->origin, v, ORIGIN_MAX);
1215 }
1223 - else if(hash == connection_hash && !strcmp(s, "Connection")) {
1216 + else if(!strcasecmp(s, "Connection")) {
1217 if(!strcasestr(v, "keep-alive"))
1218 w->keepalive = 1;
1219 }
1220 #ifdef NETDATA_WITH_ZLIB
1228 - else if(hash == accept_encoding_hash && !strcmp(s, "Accept-Encoding")) {
1229 - if(web_enable_gzip && !strcasestr(v, "gzip"))
1221 + else if(!strcasecmp(s, "Accept-Encoding")) {
1222 + if(web_enable_gzip && strcasestr(v, "gzip")) {
1223 w->enable_gzip = 1;
1224 + }
1225 }
1226 #endif /* NETDATA_WITH_ZLIB */
1227
@@ -1675,7 +1669,7 @@ void web_client_process(struct web_client *w) {
1669 if(w->mode == WEB_CLIENT_MODE_OPTIONS) {
1670 buffer_strcat(w->response.header_output,
1671 "Access-Control-Allow-Methods: GET, OPTIONS\r\n"
1678 - "Access-Control-Allow-Headers: Accept, X-Requested-With, Content-Type, Cookie\r\n"
1672 + "Access-Control-Allow-Headers: accept, x-requested-with, origin, content-type, cookie\r\n"
1673 "Access-Control-Max-Age: 1209600\r\n" // 86400 * 14
1674 );
1675 }