Skip to content

Commit 68e12d7

Browse files
committed
Merge branch 'jt/http-base-url-update-upon-redirect' into maint
When a redirected http transport gets an error during the redirected request, we ignored the error we got from the server, and ended up giving a not-so-useful error message. * jt/http-base-url-update-upon-redirect: http: attempt updating base URL only if no error
2 parents 8e87cbc + 8e27391 commit 68e12d7

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

http.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,9 @@ static int http_request_reauth(const char *url,
17691769
{
17701770
int ret = http_request(url, result, target, options);
17711771

1772+
if (ret != HTTP_OK && ret != HTTP_REAUTH)
1773+
return ret;
1774+
17721775
if (options && options->effective_url && options->base_url) {
17731776
if (update_url_from_redirect(options->base_url,
17741777
url, options->effective_url)) {

t/lib-httpd/apache.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ RewriteRule ^/ftp-redir/(.*)$ ftp://localhost:1000/$1 [R=302]
133133
RewriteRule ^/loop-redir/x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-(.*) /$1 [R=302]
134134
RewriteRule ^/loop-redir/(.*)$ /loop-redir/x-$1 [R=302]
135135

136+
# redir-to/502/x?y -> really-redir-to?path=502/x&qs=y which returns 502
137+
# redir-to/x?y -> really-redir-to?path=x&qs=y -> x?y
138+
RewriteCond %{QUERY_STRING} ^(.*)$
139+
RewriteRule ^/redir-to/(.*)$ /really-redir-to?path=$1&qs=%1 [R=302]
140+
RewriteCond %{QUERY_STRING} ^path=502/(.*)&qs=(.*)$
141+
RewriteRule ^/really-redir-to$ - [R=502,L]
142+
RewriteCond %{QUERY_STRING} ^path=(.*)&qs=(.*)$
143+
RewriteRule ^/really-redir-to$ /%1?%2 [R=302]
144+
136145
# The first rule issues a client-side redirect to something
137146
# that _doesn't_ look like a git repo. The second rule is a
138147
# server-side rewrite, so that it turns out the odd-looking

t/t5550-http-fetch-dumb.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,5 +378,14 @@ test_expect_success 'http-alternates triggers not-from-user protocol check' '
378378
clone $HTTPD_URL/dumb/evil.git evil-user
379379
'
380380

381+
test_expect_success 'can redirect through non-"info/refs?service=git-upload-pack" URL' '
382+
git clone "$HTTPD_URL/redir-to/dumb/repo.git"
383+
'
384+
385+
test_expect_success 'print HTTP error when any intermediate redirect throws error' '
386+
test_must_fail git clone "$HTTPD_URL/redir-to/502" 2> stderr &&
387+
test_i18ngrep "unable to access.*/redir-to/502" stderr
388+
'
389+
381390
stop_httpd
382391
test_done

0 commit comments

Comments
 (0)