summaryrefslogtreecommitdiffstats
path: root/net/url_request/url_request_unittest.cc
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-15 04:36:51 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-15 04:36:51 +0000
commit71c64f6be0aa9b79c0243354106a5acb68b505d8 (patch)
treee10f749f2cd3b6d3b494fa24260e1fbb3d78cb42 /net/url_request/url_request_unittest.cc
parent9504f194280791e04b468ecb518e175305757c5f (diff)
downloadchromium_src-71c64f6be0aa9b79c0243354106a5acb68b505d8.zip
chromium_src-71c64f6be0aa9b79c0243354106a5acb68b505d8.tar.gz
chromium_src-71c64f6be0aa9b79c0243354106a5acb68b505d8.tar.bz2
Don't send Content-Type when redirecting from a POST.
http://code.google.com/p/chromium/issues/detail?id=843 Review URL: http://codereview.chromium.org/10873 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5532 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request/url_request_unittest.cc')
-rw-r--r--net/url_request/url_request_unittest.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index ab5c72d..ece803e 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -58,6 +58,17 @@ std::string TestNetResourceProvider(int key) {
return "header";
}
+// Do a case-insensitive search through |haystack| for |needle|.
+bool ContainsString(const std::string& haystack, const char* needle) {
+ std::string::const_iterator it =
+ std::search(haystack.begin(),
+ haystack.end(),
+ needle,
+ needle + strlen(needle),
+ CaseInsensitiveCompare<char>());
+ return it != haystack.end();
+}
+
} // namespace
TEST(URLRequestTest, GetTest_NoCache) {
@@ -767,3 +778,43 @@ TEST(URLRequestTest, BasicAuth) {
}
}
+// In this test, we do a POST which the server will 302 redirect.
+// The subsequent transaction should use GET, and should not send the
+// Content-Type header.
+// http://code.google.com/p/chromium/issues/detail?id=843
+TEST(URLRequestTest, Post302RedirectGet) {
+ TestServer server(L"net/data/url_request_unittest");
+ TestDelegate d;
+ TestURLRequest req(server.TestServerPage("files/redirect-to-echoall"), &d);
+ req.set_method("POST");
+
+ // Set headers (some of which are specific to the POST).
+ // ("Content-Length: 10" is just a junk value to make sure it gets stripped).
+ req.SetExtraRequestHeaders(
+ "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n"
+ "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n"
+ "Accept-Language: en-US,en\r\n"
+ "Accept-Charset: ISO-8859-1,*,utf-8\r\n"
+ "Content-Length: 10\r\n"
+ "Origin: http://localhost:1337/"
+ );
+ req.Start();
+ MessageLoop::current()->Run();
+
+ std::string mime_type;
+ req.GetMimeType(&mime_type);
+ EXPECT_EQ("text/html", mime_type);
+
+ const std::string& data = d.data_received();
+
+ // Check that the post-specific headers were stripped:
+ EXPECT_FALSE(ContainsString(data, "Content-Length:"));
+ EXPECT_FALSE(ContainsString(data, "Content-Type:"));
+ EXPECT_FALSE(ContainsString(data, "Origin:"));
+
+ // These extra request headers should not have been stripped.
+ EXPECT_TRUE(ContainsString(data, "Accept:"));
+ EXPECT_TRUE(ContainsString(data, "Accept-Language:"));
+ EXPECT_TRUE(ContainsString(data, "Accept-Charset:"));
+}
+