* Re: [PATCH] smart-http: Don't change POST to GET when following redirect
2010-09-18 8:47 ` [PATCH] smart-http: Don't change POST to GET when following redirect Andreas Schwab
@ 2010-09-18 14:09 ` Miles Bader
2010-09-18 21:00 ` Jay Soffian
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Miles Bader @ 2010-09-18 14:09 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Ilari Liusvaara, git
Thanks Andreas!
-miles
--
Acquaintance, n. A person whom we know well enough to borrow from, but not
well enough to lend to.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] smart-http: Don't change POST to GET when following redirect
2010-09-18 8:47 ` [PATCH] smart-http: Don't change POST to GET when following redirect Andreas Schwab
2010-09-18 14:09 ` Miles Bader
@ 2010-09-18 21:00 ` Jay Soffian
2010-09-24 6:20 ` [PATCH v2] " Tay Ray Chuan
2010-09-25 4:20 ` [PATCH v3] " Tay Ray Chuan
3 siblings, 0 replies; 9+ messages in thread
From: Jay Soffian @ 2010-09-18 21:00 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Ilari Liusvaara, Miles Bader, git
On Sat, Sep 18, 2010 at 4:47 AM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> + curl_easy_setopt(slot->curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
Not sure what git's minimum supported libcurl is, but this define was
added in 7.19.1 (November 5 2008).
j.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] smart-http: Don't change POST to GET when following redirect
2010-09-18 8:47 ` [PATCH] smart-http: Don't change POST to GET when following redirect Andreas Schwab
2010-09-18 14:09 ` Miles Bader
2010-09-18 21:00 ` Jay Soffian
@ 2010-09-24 6:20 ` Tay Ray Chuan
2010-09-24 18:06 ` Andreas Schwab
2010-09-25 4:20 ` [PATCH v3] " Tay Ray Chuan
3 siblings, 1 reply; 9+ messages in thread
From: Tay Ray Chuan @ 2010-09-24 6:20 UTC (permalink / raw)
To: Git Mailing List
Cc: Junio C Hamano, Andreas Schwab, Jay Soffian, Ilari Liusvaara,
Miles Bader
From: Andreas Schwab <schwab@linux-m68k.org>
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.
Signed-off-by: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
Added simple tests and made some changes to the patch message.
Andreas:
shifted the setopt to right after FOLLOWLOCATION, since they're linked
closely.
Jay: added the usual hexadecimal version checks.
http.c | 3 +++
t/lib-httpd/apache.conf | 7 +++++++
t/t5551-http-fetch.sh | 8 ++++++++
3 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/http.c b/http.c
index 1320c50..25f8b45 100644
--- a/http.c
+++ b/http.c
@@ -275,6 +275,9 @@ static CURL *get_curl_handle(void)
}
curl_easy_setopt(result, CURLOPT_FOLLOWLOCATION, 1);
+#if LIBCURL_VERSION_NUM >= 0x071301
+ curl_easy_setopt(result, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
+#endif
if (getenv("GIT_CURL_VERBOSE"))
curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf
index 4961505..f41c7c6 100644
--- a/t/lib-httpd/apache.conf
+++ b/t/lib-httpd/apache.conf
@@ -17,6 +17,9 @@ ErrorLog error.log
<IfModule !mod_env.c>
LoadModule env_module modules/mod_env.so
</IfModule>
+<IfModule !mod_rewrite.c>
+ LoadModule rewrite_module modules/mod_rewrite.so
+</IFModule>
Alias /dumb/ www/
@@ -36,6 +39,10 @@ ScriptAlias /smart_noexport/ ${GIT_EXEC_PATH}/git-http-backend/
Options ExecCGI
</Files>
+RewriteEngine on
+RewriteRule ^/smart-redir-perm/(.*)$ /smart/$1 [R=301]
+RewriteRule ^/smart-redir-temp/(.*)$ /smart/$1 [R=302]
+
<IfDefine SSL>
LoadModule ssl_module modules/mod_ssl.so
diff --git a/t/t5551-http-fetch.sh b/t/t5551-http-fetch.sh
index fd19121..26d3557 100755
--- a/t/t5551-http-fetch.sh
+++ b/t/t5551-http-fetch.sh
@@ -101,5 +101,13 @@ test_expect_success 'used upload-pack service' '
test_cmp exp act
'
+test_expect_success 'follow redirects (301)' '
+ git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
+'
+
+test_expect_success 'follow redirects (302)' '
+ git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
+'
+
stop_httpd
test_done
--
1.7.3.67.g2a10b
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2] smart-http: Don't change POST to GET when following redirect
2010-09-24 6:20 ` [PATCH v2] " Tay Ray Chuan
@ 2010-09-24 18:06 ` Andreas Schwab
0 siblings, 0 replies; 9+ messages in thread
From: Andreas Schwab @ 2010-09-24 18:06 UTC (permalink / raw)
To: Tay Ray Chuan
Cc: Git Mailing List, Junio C Hamano, Jay Soffian, Ilari Liusvaara,
Miles Bader
Tay Ray Chuan <rctay89@gmail.com> writes:
> diff --git a/http.c b/http.c
> index 1320c50..25f8b45 100644
> --- a/http.c
> +++ b/http.c
> @@ -275,6 +275,9 @@ static CURL *get_curl_handle(void)
> }
>
> curl_easy_setopt(result, CURLOPT_FOLLOWLOCATION, 1);
> +#if LIBCURL_VERSION_NUM >= 0x071301
> + curl_easy_setopt(result, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
> +#endif
Should this fall back to CURLOPT_POST301 on older versions? (Those
won't handle 302 though, I think.)
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3] smart-http: Don't change POST to GET when following redirect
2010-09-18 8:47 ` [PATCH] smart-http: Don't change POST to GET when following redirect Andreas Schwab
` (2 preceding siblings ...)
2010-09-24 6:20 ` [PATCH v2] " Tay Ray Chuan
@ 2010-09-25 4:20 ` Tay Ray Chuan
3 siblings, 0 replies; 9+ messages in thread
From: Tay Ray Chuan @ 2010-09-25 4:20 UTC (permalink / raw)
To: Git Mailing List
Cc: Junio C Hamano, Andreas Schwab, Jay Soffian, Ilari Liusvaara,
Miles Bader
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>
---
Andreas: added CURLOPT_POST301 alternative. There doesn't seem to be a pretty
constant, the docs just say a non-zero value [1] or 1 [2].
[1] http://github.com/bagder/curl/blob/curl-7_17_1/docs/libcurl/curl_easy_setopt.3#L646
[2] http://github.com/bagder/curl/blob/curl-7_19_0/docs/libcurl/curl_easy_setopt.3#L699
http.c | 5 +++++
t/lib-httpd/apache.conf | 7 +++++++
t/t5551-http-fetch.sh | 8 ++++++++
3 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/http.c b/http.c
index 1320c50..d10e2f0 100644
--- a/http.c
+++ b/http.c
@@ -275,6 +275,11 @@ static CURL *get_curl_handle(void)
}
curl_easy_setopt(result, CURLOPT_FOLLOWLOCATION, 1);
+#if LIBCURL_VERSION_NUM >= 0x071301
+ curl_easy_setopt(result, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
+#elif LIBCURL_VERSION_NUM >= 0x071101
+ curl_easy_setopt(result, CURLOPT_POST301, 1);
+#endif
if (getenv("GIT_CURL_VERBOSE"))
curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf
index 4961505..f41c7c6 100644
--- a/t/lib-httpd/apache.conf
+++ b/t/lib-httpd/apache.conf
@@ -17,6 +17,9 @@ ErrorLog error.log
<IfModule !mod_env.c>
LoadModule env_module modules/mod_env.so
</IfModule>
+<IfModule !mod_rewrite.c>
+ LoadModule rewrite_module modules/mod_rewrite.so
+</IFModule>
Alias /dumb/ www/
@@ -36,6 +39,10 @@ ScriptAlias /smart_noexport/ ${GIT_EXEC_PATH}/git-http-backend/
Options ExecCGI
</Files>
+RewriteEngine on
+RewriteRule ^/smart-redir-perm/(.*)$ /smart/$1 [R=301]
+RewriteRule ^/smart-redir-temp/(.*)$ /smart/$1 [R=302]
+
<IfDefine SSL>
LoadModule ssl_module modules/mod_ssl.so
diff --git a/t/t5551-http-fetch.sh b/t/t5551-http-fetch.sh
index fd19121..26d3557 100755
--- a/t/t5551-http-fetch.sh
+++ b/t/t5551-http-fetch.sh
@@ -101,5 +101,13 @@ test_expect_success 'used upload-pack service' '
test_cmp exp act
'
+test_expect_success 'follow redirects (301)' '
+ git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
+'
+
+test_expect_success 'follow redirects (302)' '
+ git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
+'
+
stop_httpd
test_done
--
1.7.3.67.g2a10b
^ permalink raw reply related [flat|nested] 9+ messages in thread