Commit bbb011f6 authored by mmenke@chromium.org's avatar mmenke@chromium.org

Don't convert HEAD requests to GETs on 303 redirects.

BUG=102130
TEST=URLRequestTestHTTP.Redirect*Tests

Review URL: http://codereview.chromium.org/8418024

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108060 0039d316-1c4b-4281-b951-d872f2087c98
parent b61f62a7
This diff is collapsed.
...@@ -695,15 +695,16 @@ int URLRequest::Redirect(const GURL& location, int http_status_code) { ...@@ -695,15 +695,16 @@ int URLRequest::Redirect(const GURL& location, int http_status_code) {
return ERR_UNSAFE_REDIRECT; return ERR_UNSAFE_REDIRECT;
} }
// For 303 redirects, all request methods are converted to GETs, as per RFC // For 303 redirects, all request methods except HEAD are converted to GET,
// 2616. The latest httpbis draft also allows POST requests to be converted // as per the latest httpbis draft. The draft also allows POST requests to
// to GETs when following 301/302 redirects for historical reasons. Most // be converted to GETs when following 301/302 redirects, for historical
// major browsers do this and so shall we. The RFC says to prompt the user // reasons. Most major browsers do this and so shall we. Both RFC 2616 and
// to confirm the generation of new requests, other than GET and HEAD // the httpbis draft say to prompt the user to confirm the generation of new
// requests, but IE omits these prompts and so shall we. // requests, other than GET and HEAD requests, but IE omits these prompts and
// See: http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p2-semantics-latest.html#status.3xx // so shall we.
// See: https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-17#section-7.3
bool was_post = method_ == "POST"; bool was_post = method_ == "POST";
if (http_status_code == 303 || if ((http_status_code == 303 && method_ != "HEAD") ||
((http_status_code == 301 || http_status_code == 302) && was_post)) { ((http_status_code == 301 || http_status_code == 302) && was_post)) {
method_ = "GET"; method_ = "GET";
upload_ = NULL; upload_ = NULL;
......
...@@ -2473,7 +2473,8 @@ TEST_F(URLRequestTestHTTP, Post302RedirectGet) { ...@@ -2473,7 +2473,8 @@ TEST_F(URLRequestTestHTTP, Post302RedirectGet) {
} }
// The following tests check that we handle mutating the request method for // The following tests check that we handle mutating the request method for
// HTTP redirects as expected. See http://crbug.com/56373. // HTTP redirects as expected.
// See http://crbug.com/56373 and http://crbug.com/102130.
TEST_F(URLRequestTestHTTP, Redirect301Tests) { TEST_F(URLRequestTestHTTP, Redirect301Tests) {
ASSERT_TRUE(test_server_.Start()); ASSERT_TRUE(test_server_.Start());
...@@ -2482,6 +2483,7 @@ TEST_F(URLRequestTestHTTP, Redirect301Tests) { ...@@ -2482,6 +2483,7 @@ TEST_F(URLRequestTestHTTP, Redirect301Tests) {
HTTPRedirectMethodTest(url, "POST", "GET", true); HTTPRedirectMethodTest(url, "POST", "GET", true);
HTTPRedirectMethodTest(url, "PUT", "PUT", true); HTTPRedirectMethodTest(url, "PUT", "PUT", true);
HTTPRedirectMethodTest(url, "HEAD", "HEAD", false);
} }
TEST_F(URLRequestTestHTTP, Redirect302Tests) { TEST_F(URLRequestTestHTTP, Redirect302Tests) {
...@@ -2491,6 +2493,7 @@ TEST_F(URLRequestTestHTTP, Redirect302Tests) { ...@@ -2491,6 +2493,7 @@ TEST_F(URLRequestTestHTTP, Redirect302Tests) {
HTTPRedirectMethodTest(url, "POST", "GET", true); HTTPRedirectMethodTest(url, "POST", "GET", true);
HTTPRedirectMethodTest(url, "PUT", "PUT", true); HTTPRedirectMethodTest(url, "PUT", "PUT", true);
HTTPRedirectMethodTest(url, "HEAD", "HEAD", false);
} }
TEST_F(URLRequestTestHTTP, Redirect303Tests) { TEST_F(URLRequestTestHTTP, Redirect303Tests) {
...@@ -2500,6 +2503,7 @@ TEST_F(URLRequestTestHTTP, Redirect303Tests) { ...@@ -2500,6 +2503,7 @@ TEST_F(URLRequestTestHTTP, Redirect303Tests) {
HTTPRedirectMethodTest(url, "POST", "GET", true); HTTPRedirectMethodTest(url, "POST", "GET", true);
HTTPRedirectMethodTest(url, "PUT", "GET", true); HTTPRedirectMethodTest(url, "PUT", "GET", true);
HTTPRedirectMethodTest(url, "HEAD", "HEAD", false);
} }
TEST_F(URLRequestTestHTTP, Redirect307Tests) { TEST_F(URLRequestTestHTTP, Redirect307Tests) {
...@@ -2509,6 +2513,7 @@ TEST_F(URLRequestTestHTTP, Redirect307Tests) { ...@@ -2509,6 +2513,7 @@ TEST_F(URLRequestTestHTTP, Redirect307Tests) {
HTTPRedirectMethodTest(url, "POST", "POST", true); HTTPRedirectMethodTest(url, "POST", "POST", true);
HTTPRedirectMethodTest(url, "PUT", "PUT", true); HTTPRedirectMethodTest(url, "PUT", "PUT", true);
HTTPRedirectMethodTest(url, "HEAD", "HEAD", false);
} }
TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment