@cryptotaxi247 / netdata-1 / commits / b628b07f3

Redirect when url =~ \/host\/hostname$ (#7539) (#7643)

* Redirect when url =~ \/host\/hostname$ (#7539)

Timo committed Jan 4, 2020 at 11:10 UTC b628b07f3c014925f5063c8b781b6bc858864a50
1 file changed +8
web/server/web_client.c
+8
@@ -1339,8 +1339,16 @@ static inline int web_client_switch_host(RRDHOST *host, struct web_client *w, ch
1339 if(tok && *tok) {
1340 debug(D_WEB_CLIENT, "%llu: Searching for host with name '%s'.", w->id, tok);
1341
1342 + if(!url) { //no delim found
1343 + debug(D_WEB_CLIENT, "%llu: URL doesn't end with / generating redirect.", w->id);
1344 + buffer_sprintf(w->response.header, "Location: http://%s%s/\r\n", w->server_host, w->last_url);
1345 + buffer_strcat(w->response.data, "Permanent redirect");
1346 + return HTTP_RESP_REDIR_PERM;
1347 + }
1348 +
1349 // copy the URL, we need it to serve files
1350 w->last_url[0] = '/';
1351 +
1352 if(url && *url) strncpyz(&w->last_url[1], url, NETDATA_WEB_REQUEST_URL_SIZE - 1);
1353 else w->last_url[1] = '\0';
1354