updated config option for application redirects at the registry and commented the unused code of native 307 redirects
Costa Tsaousis committed
Jun 2, 2016 at 19:05 UTC
9e2554975fb63e538ab05155cbc4119085a8774e
2 files changed
+22
-15
src/registry.c
+1
-5
@@ -1666,11 +1666,7 @@ int registry_init(void) {
1666
registry.registry_to_announce = config_get("registry", "registry to announce", "https://registry.my-netdata.io");
1667
registry.hostname = config_get("registry", "registry hostname", config_get("global", "hostname", hostname));
1668
1669
- registry.verify_cookies_redirects = config_get_number("registry", "verify browser cookies support max redirects", 2);
1670
- if(registry.verify_cookies_redirects < 0) {
1671
- registry.verify_cookies_redirects = 0;
1672
- config_set_number("registry", "verify browser cookies support max redirects", registry.verify_cookies_redirects);
1673
- }
1669
+ registry.verify_cookies_redirects = config_get_boolean("registry", "verify browser cookies support max redirects", 1);
1670
1671
registry.max_url_length = config_get_number("registry", "max URL length", 1024);
1672
if(registry.max_url_length < 10) {
src/web_client.c
+21
-10
@@ -862,7 +862,7 @@ int web_client_api_request_v1_registry(struct web_client *w, char *url)
862
{
863
static uint32_t hash_action = 0, hash_access = 0, hash_hello = 0, hash_delete = 0, hash_search = 0,
864
hash_switch = 0, hash_machine = 0, hash_url = 0, hash_name = 0, hash_delete_url = 0, hash_for = 0,
865
- hash_to = 0, hash_redirects = 0;
865
+ hash_to = 0 /*, hash_redirects = 0 */;
866
867
if(unlikely(!hash_action)) {
868
hash_action = simple_hash("action");
@@ -877,7 +877,9 @@ int web_client_api_request_v1_registry(struct web_client *w, char *url)
877
hash_delete_url = simple_hash("delete_url");
878
hash_for = simple_hash("for");
879
hash_to = simple_hash("to");
880
+/*
881
hash_redirects = simple_hash("redirects");
882
+*/
883
}
884
885
char person_guid[36 + 1] = "";
@@ -898,7 +900,9 @@ int web_client_api_request_v1_registry(struct web_client *w, char *url)
900
*search_machine_guid = NULL,
901
*delete_url = NULL,
902
*to_person_guid = NULL;
903
+/*
904
int redirects = 0;
905
+*/
906
907
while(url) {
908
char *value = mystrsep(&url, "?&[]");
@@ -924,9 +928,10 @@ int web_client_api_request_v1_registry(struct web_client *w, char *url)
928
else error("unknown registry action '%s'", value);
929
#endif /* NETDATA_INTERNAL_CHECKS */
930
}
931
+/*
932
else if(hash == hash_redirects && !strcmp(name, "redirects"))
933
redirects = atoi(value);
929
-
934
+*/
935
else if(hash == hash_machine && !strcmp(name, "machine"))
936
machine_guid = value;
937
@@ -984,18 +989,24 @@ int web_client_api_request_v1_registry(struct web_client *w, char *url)
989
if(registry_verify_cookies_redirects() > 0 && (!cookie || !person_guid[0])) {
990
buffer_flush(w->response.data);
991
987
- if(redirects > registry_verify_cookies_redirects()) {
988
- buffer_sprintf(w->response.data, "Your browser does not support cookies");
989
- return 400;
990
- }
991
-
992
- redirects++;
993
-
992
registry_set_cookie(w, "give-me-back-this-cookie-please");
993
w->response.data->contenttype = CT_APPLICATION_JSON;
994
buffer_sprintf(w->response.data, "{ \"status\": \"redirect\", \"registry\": \"%s\" }", registry_to_announce());
995
+ return 200;
996
997
/*
998
+ * it seems that web browsers are ignoring 307 (Moved Temporarily)
999
+ * under certain conditions, when using CORS
1000
+ * so this is commented and we use application level redirects instead
1001
+ *
1002
+ redirects++;
1003
+
1004
+ if(redirects > registry_verify_cookies_redirects()) {
1005
+ buffer_flush(w->response.data);
1006
+ buffer_sprintf(w->response.data, "Your browser does not support cookies");
1007
+ return 400;
1008
+ }
1009
+
1010
char *encoded_url = url_encode(machine_url);
1011
if(!encoded_url) {
1012
error("%llu: Cannot URL encode string '%s'", w->id, machine_url);
@@ -1023,8 +1034,8 @@ int web_client_api_request_v1_registry(struct web_client *w, char *url)
1034
free(encoded_guid);
1035
free(encoded_name);
1036
free(encoded_url);
1037
+ return 307
1038
*/
1027
- return 200;
1039
}
1040
return registry_request_access_json(w, person_guid, machine_guid, machine_url, url_name, time(NULL));
1041