diff options
author | Ben Straub <bs@github.com> | 2013-09-23 23:09:23 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-09-24 22:18:36 +0400 |
commit | 210d5325262fb8d5ae553fcdba6f3c045db3e1de (patch) | |
tree | 12ca2a023580d2513224a89f7babec28e7d9c5d8 /src/transports | |
parent | 4a1b40159b4b0b2a954d40e4489331e3f22c8994 (diff) |
Allow redirects to use same host
Diffstat (limited to 'src/transports')
-rw-r--r-- | src/transports/http.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/transports/http.c b/src/transports/http.c index eca06ead2..ab42a3c08 100644 --- a/src/transports/http.c +++ b/src/transports/http.c @@ -303,15 +303,28 @@ static int on_headers_complete(http_parser *parser) parser->status_code == 307) && t->location) { + char *host=NULL, *port=NULL, *user=NULL, *pass=NULL; + if (s->redirect_count >= 7) { giterr_set(GITERR_NET, "Too many redirects"); return t->parse_error = PARSE_ERROR_GENERIC; } - if (t->location[0] != '/') { - giterr_set(GITERR_NET, "Only relative redirects are supported"); + if (gitno_extract_url_parts(&host, &port, &user, &pass, t->location, "") < 0) { + giterr_set(GITERR_NET, "Redirect to unparseable url '%s'", t->location); + return t->parse_error = PARSE_ERROR_GENERIC; + } + git__free(port); + git__free(user); + git__free(pass); + + /* Allow '/'-led urls, or a change of protocol */ + if (strcmp(t->host, host) && t->location[0] != '/') { + git__free(host); + giterr_set(GITERR_NET, "Only same-host redirects are supported"); return t->parse_error = PARSE_ERROR_GENERIC; } + git__free(host); /* Set the redirect URL on the stream. This is a transfer of * ownership of the memory. */ |