@matheusbsbs / matheus-bagliano / commits / 703e6e76a1
Fork 0

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 <rctay89@gmail.com> Reported-and-tested-by: Yaroslav Halchenko <debian@onerussian.com> Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tay Ray Chuan committed Jan 21, 2010 at 22:41 UTC 703e6e76a14825e5b0c960d525f34e607154b4f7
1 file changed +16 -2
remote-curl.c
+16 -2
@@ -102,7 +102,7 @@ static struct discovery* discover_refs(const char *service)
102 struct strbuf buffer = STRBUF_INIT;
103 struct discovery *last = last_discovery;
104 char *refs_url;
105 - int http_ret, is_http = 0;
105 + int http_ret, is_http = 0, proto_git_candidate = 1;
106
107 if (last && !strcmp(service, last->service))
108 return last;
@@ -121,6 +121,19 @@ static struct discovery* discover_refs(const char *service)
121
122 init_walker();
123 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 +
137 switch (http_ret) {
138 case HTTP_OK:
139 break;
@@ -137,7 +150,8 @@ static struct discovery* discover_refs(const char *service)
150 last->buf_alloc = strbuf_detach(&buffer, &last->len);
151 last->buf = last->buf_alloc;
152
140 - if (is_http && 5 <= last->len && last->buf[4] == '#') {
153 + if (is_http && proto_git_candidate
154 + && 5 <= last->len && last->buf[4] == '#') {
155 /* smart HTTP response; validate that the service
156 * pkt-line matches our request.
157 */