Skip to content

Commit 703e6e7

Browse files
rctaygitster
authored andcommitted
retry request without query when info/refs?query fails
When "info/refs" is a static file and not behind a CGI handler, some servers may not handle a GET request for it with a query string appended (eg. "?foo=bar") properly. If such a request fails, retry it sans the query string. In addition, ensure that the "smart" http protocol is not used (a service has to be specified with "?service=<service name>" to be conformant). Signed-off-by: Tay Ray Chuan <[email protected]> Reported-and-tested-by: Yaroslav Halchenko <[email protected]> Acked-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f376a5 commit 703e6e7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

remote-curl.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static struct discovery* discover_refs(const char *service)
102102
struct strbuf buffer = STRBUF_INIT;
103103
struct discovery *last = last_discovery;
104104
char *refs_url;
105-
int http_ret, is_http = 0;
105+
int http_ret, is_http = 0, proto_git_candidate = 1;
106106

107107
if (last && !strcmp(service, last->service))
108108
return last;
@@ -121,6 +121,19 @@ static struct discovery* discover_refs(const char *service)
121121

122122
init_walker();
123123
http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
124+
125+
/* try again with "plain" url (no ? or & appended) */
126+
if (http_ret != HTTP_OK) {
127+
free(refs_url);
128+
strbuf_reset(&buffer);
129+
130+
proto_git_candidate = 0;
131+
strbuf_addf(&buffer, "%s/info/refs", url);
132+
refs_url = strbuf_detach(&buffer, NULL);
133+
134+
http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
135+
}
136+
124137
switch (http_ret) {
125138
case HTTP_OK:
126139
break;
@@ -137,7 +150,8 @@ static struct discovery* discover_refs(const char *service)
137150
last->buf_alloc = strbuf_detach(&buffer, &last->len);
138151
last->buf = last->buf_alloc;
139152

140-
if (is_http && 5 <= last->len && last->buf[4] == '#') {
153+
if (is_http && proto_git_candidate
154+
&& 5 <= last->len && last->buf[4] == '#') {
141155
/* smart HTTP response; validate that the service
142156
* pkt-line matches our request.
143157
*/

0 commit comments

Comments
 (0)