Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
http: fix the webroot redirections
  • Loading branch information
perexg committed Sep 15, 2015
1 parent 73fc487 commit 9b8fc6f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/http.c
Expand Up @@ -462,10 +462,11 @@ http_redirect(http_connection_t *hc, const char *location,
if (!external && tvheadend_webroot && location[0] == '/')
htsbuf_append(&hq, tvheadend_webroot, strlen(tvheadend_webroot));
htsbuf_append(&hq, location, strlen(location));
htsbuf_append(&hq, "?", 1);
TAILQ_FOREACH(ra, req_args, link) {
if (!first)
htsbuf_append(&hq, "&", 1);
else
htsbuf_append(&hq, "?", 1);
first = 0;
htsbuf_append_and_escape_url(&hq, ra->key);
htsbuf_append(&hq, "=", 1);
Expand Down
20 changes: 18 additions & 2 deletions src/webui/webui.c
Expand Up @@ -143,8 +143,24 @@ page_root(http_connection_t *hc, const char *remain, void *opaque)
static int
page_root2(http_connection_t *hc, const char *remain, void *opaque)
{
if (!tvheadend_webroot) return 1;
http_redirect(hc, "/", &hc->hc_req_args, 0);
size_t l;
char *s;

/* not found checks */
if (!tvheadend_webroot)
return HTTP_STATUS_NOT_FOUND;
l = strlen(tvheadend_webroot);
if (strncmp(hc->hc_url, tvheadend_webroot, l) == 0 &&
hc->hc_url[l] == '/')
return HTTP_STATUS_NOT_FOUND;

/* redirect if url is not in the specified webroot */
if (!remain)
remain = "";
s = alloca(2 + strlen(remain));
s[0] = '/';
strcpy(s + 1, remain);
http_redirect(hc, s, &hc->hc_req_args, 0);
return 0;
}

Expand Down

0 comments on commit 9b8fc6f

Please sign in to comment.