Skip to content

Commit 311e2ea

Browse files
rctaygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Tay Ray Chuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9027fa9 commit 311e2ea

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

http.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ static CURL *get_curl_handle(void)
279279
}
280280

281281
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
282287

283288
if (getenv("GIT_CURL_VERBOSE"))
284289
curl_easy_setopt(result, CURLOPT_VERBOSE, 1);

t/lib-httpd/apache.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ ErrorLog error.log
1717
<IfModule !mod_env.c>
1818
LoadModule env_module modules/mod_env.so
1919
</IfModule>
20+
<IfModule !mod_rewrite.c>
21+
LoadModule rewrite_module modules/mod_rewrite.so
22+
</IFModule>
2023

2124
Alias /dumb/ www/
2225

@@ -36,6 +39,10 @@ ScriptAlias /smart_noexport/ ${GIT_EXEC_PATH}/git-http-backend/
3639
Options ExecCGI
3740
</Files>
3841

42+
RewriteEngine on
43+
RewriteRule ^/smart-redir-perm/(.*)$ /smart/$1 [R=301]
44+
RewriteRule ^/smart-redir-temp/(.*)$ /smart/$1 [R=302]
45+
3946
<IfDefine SSL>
4047
LoadModule ssl_module modules/mod_ssl.so
4148

t/t5551-http-fetch.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,13 @@ test_expect_success 'used upload-pack service' '
101101
test_cmp exp act
102102
'
103103

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+
104112
stop_httpd
105113
test_done

0 commit comments

Comments
 (0)