smart-http: Don't change POST to GET when following redirect
For a long time (29508e1 "Isolate shared HTTP request functionality", Fri Nov 18 11:02:58 2005), we've followed HTTP redirects with CURLOPT_FOLLOWLOCATION. However, when the remote HTTP server returns a redirect the default libcurl action is to change a POST request into a GET request while following the redirect, but the remote http backend does not expect that. Fix this by telling libcurl to always keep the request as type POST with CURLOPT_POSTREDIR. For users of libcurl older than 7.19.1, use CURLOPT_POST301 instead, which only follows 301s instead of both 301s and 302s. Signed-off-by: Andreas Schwab <schwab@linux-m68k.org> Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Tay Ray Chuan committed
Sep 25, 2010 at 12:20 UTC
311e2ea0062bf09d6f78f5458eeb14dbc6c092ea
3 files changed
+20
http.c
+5
@@ -279,6 +279,11 @@ static CURL *get_curl_handle(void)
279
}
280
281
curl_easy_setopt(result, CURLOPT_FOLLOWLOCATION, 1);
282
+#if LIBCURL_VERSION_NUM >= 0x071301
283
+ curl_easy_setopt(result, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
284
+#elif LIBCURL_VERSION_NUM >= 0x071101
285
+ curl_easy_setopt(result, CURLOPT_POST301, 1);
286
+#endif
287
288
if (getenv("GIT_CURL_VERBOSE"))
289
curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
t/lib-httpd/apache.conf
+7
@@ -17,6 +17,9 @@ ErrorLog error.log
17
<IfModule !mod_env.c>
18
LoadModule env_module modules/mod_env.so
19
</IfModule>
20
+<IfModule !mod_rewrite.c>
21
+ LoadModule rewrite_module modules/mod_rewrite.so
22
+</IFModule>
23
24
Alias /dumb/ www/
25
@@ -36,6 +39,10 @@ ScriptAlias /smart_noexport/ ${GIT_EXEC_PATH}/git-http-backend/
39
Options ExecCGI
40
</Files>
41
42
+RewriteEngine on
43
+RewriteRule ^/smart-redir-perm/(.*)$ /smart/$1 [R=301]
44
+RewriteRule ^/smart-redir-temp/(.*)$ /smart/$1 [R=302]
45
+
46
<IfDefine SSL>
47
LoadModule ssl_module modules/mod_ssl.so
48
t/t5551-http-fetch.sh
+8
@@ -101,5 +101,13 @@ test_expect_success 'used upload-pack service' '
101
test_cmp exp act
102
'
103
104
+test_expect_success 'follow redirects (301)' '
105
+ git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
106
+'
107
+
108
+test_expect_success 'follow redirects (302)' '
109
+ git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
110
+'
111
+
112
stop_httpd
113
test_done