All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tay Ray Chuan <rctay89@gmail.com>
To: "Git Mailing List" <git@vger.kernel.org>
Cc: "Junio C Hamano" <gitster@pobox.com>,
	Andreas Schwab <schwab@linux-m68k.org>,
	Jay Soffian <jaysoffian@gmail.com>,
	Ilari Liusvaara <ilari.liusvaara@elisanet.fi>,
	Miles Bader <miles@gnu.org>
Subject: [PATCH v2] smart-http: Don't change POST to GET when following redirect
Date: Fri, 24 Sep 2010 14:20:23 +0800	[thread overview]
Message-ID: <1285309223-4348-1-git-send-email-rctay89@gmail.com> (raw)
In-Reply-To: <AANLkTimwkXTs==+zT=Ue3jFNyRLL+7A1FFhoDuF-5zZ3@mail.gmail.com>

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

  reply	other threads:[~2010-09-24  6:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-18  4:33 git "smart http" server vs. http redirects Miles Bader
2010-09-18  7:03 ` Ilari Liusvaara
2010-09-18  8:16   ` Andreas Schwab
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 [this message]
2010-09-24 18:06           ` [PATCH v2] " Andreas Schwab
2010-09-25  4:20             ` [PATCH v3] " Tay Ray Chuan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1285309223-4348-1-git-send-email-rctay89@gmail.com \
    --to=rctay89@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=ilari.liusvaara@elisanet.fi \
    --cc=jaysoffian@gmail.com \
    --cc=miles@gnu.org \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.