diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Keep the query string across the about redirects
The hop to the trailing-slash form of the about page, and the hop back
to the summary of a repository without a readme, were built from the
path alone, so a request for the about page of another branch landed
on the default one. The query goes into the Location line as the
client sent it, with any byte a header cannot carry percent-encoded.
Diffstat (limited to 'source/ui-shared.c')
| -rw-r--r-- | source/ui-shared.c | 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 15 insertions, 6 deletions
diff --git a/source/ui-shared.c b/source/ui-shared.c index 0f2f1e3..147472e 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -828,16 +828,15 @@ char *cgit_currenturl(void) return cgit_fmtalloc("%s/%s", root, ctx.qry.url); } -char *cgit_currentfullurl(void) +char *cgit_currentquery(void) { - const char *root = root_url(); const char *orig_query = ctx.env.query_string ? ctx.env.query_string : ""; size_t len = strlen(orig_query); char *query = xmalloc(len + 2); - char *match, *ret; + char *match; - // The url argument carried the path into this request and the path is - // spelled out again below, so it is dropped here. The copy keeps a + // The url argument carried the path into this request and every caller + // spells the path out again, so it is dropped here. The copy keeps a // leading question mark so that every match has a character before it, // which is what tells the argument itself from the tail of another one. memcpy(query + 1, orig_query, len + 1); @@ -856,6 +855,14 @@ char *cgit_currentfullurl(void) } if (!query[1]) query[0] = '\0'; + return query; +} + +char *cgit_currentfullurl(void) +{ + const char *root = root_url(); + char *query = cgit_currentquery(); + char *ret; if (!ctx.qry.url) ret = cgit_fmtalloc("%s%s", root, query); @@ -1453,11 +1460,13 @@ void cgit_print_http_headers(void) exit(0); } -void cgit_redirect(const char *url, bool permanent) +void cgit_redirect(const char *url, const char *query, bool permanent) { htmlf("Status: %d %s\n", permanent ? 301 : 302, permanent ? "Moved Permanently" : "Found"); html("Location: "); html_url_path(url); + if (query) + html_header_query(query); html("\n\n"); } |
