Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Unified Diff: net/http/http_network_layer_unittest.cc

Issue 99283006: Retry idempotent methods on Chrome-Proxy: bypass (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/http/http_network_transaction.cc » ('j') | net/http/http_network_transaction.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_network_layer_unittest.cc
diff --git a/net/http/http_network_layer_unittest.cc b/net/http/http_network_layer_unittest.cc
index fc5b43cd841e2f8f45ff42d57e75bf39e20f4654..72aeecfcd25eb6f6b0ad95d33d972bf3095b4ee7 100644
--- a/net/http/http_network_layer_unittest.cc
+++ b/net/http/http_network_layer_unittest.cc
@@ -54,14 +54,15 @@ class HttpNetworkLayerTest : public PlatformTest {
}
#endif
- void ExecuteRequestExpectingContentAndHeader(const std::string& content,
+ void ExecuteRequestExpectingContentAndHeader(const std::string& method,
+ const std::string& content,
const std::string& header,
const std::string& value) {
TestCompletionCallback callback;
HttpRequestInfo request_info;
request_info.url = GURL("http://www.google.com/");
- request_info.method = "GET";
+ request_info.method = method;
request_info.load_flags = LOAD_NORMAL;
scoped_ptr<HttpTransaction> trans;
@@ -114,10 +115,30 @@ class HttpNetworkLayerTest : public PlatformTest {
void TestProxyFallbackWithMockReads(const std::string& bad_proxy,
MockRead data_reads[],
int data_reads_size) {
+ TestProxyFallbackByMethodWithMockReads(bad_proxy, data_reads,
+ data_reads_size,
+ "GET", "content", true);
+
+ }
+
+ void TestProxyFallbackByMethodWithMockReads(const std::string& bad_proxy,
+ MockRead data_reads[],
+ int data_reads_size,
+ std::string method,
+ std::string content,
+ bool retry_expected) {
+
+ std::string trailer =
+ (method == "HEAD" || method == "PUT" || method == "POST") ?
+ "Content-Length: 0\r\n\r\n" : "\r\n";
+ std::string request =
+ base::StringPrintf("%s http://www.google.com/ HTTP/1.1\r\n"
+ "Host: www.google.com\r\n"
+ "Proxy-Connection: keep-alive\r\n"
+ "%s", method.c_str(), trailer.c_str());
+
MockWrite data_writes[] = {
- MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
- "Host: www.google.com\r\n"
- "Proxy-Connection: keep-alive\r\n\r\n"),
+ MockWrite(request.c_str()),
};
StaticSocketDataProvider data1(data_reads, data_reads_size,
@@ -125,24 +146,30 @@ class HttpNetworkLayerTest : public PlatformTest {
mock_socket_factory_.AddSocketDataProvider(&data1);
// Second data provider returns the expected content.
- MockRead data_reads2[] = {
- MockRead("HTTP/1.0 200 OK\r\n"
- "Server: not-proxy\r\n\r\n"),
- MockRead("content"),
- MockRead(SYNCHRONOUS, OK),
- };
+ MockRead data_reads2[3];
+ size_t data_reads2_index = 0;
+ data_reads2[data_reads2_index++] = MockRead("HTTP/1.0 200 OK\r\n"
+ "Server: not-proxy\r\n\r\n");
+ if (!content.empty())
+ data_reads2[data_reads2_index++] = MockRead(content.c_str());
+ data_reads2[data_reads2_index++] = MockRead(SYNCHRONOUS, OK);
+
+
MockWrite data_writes2[] = {
- MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
- "Host: www.google.com\r\n"
- "Proxy-Connection: keep-alive\r\n\r\n"),
+ MockWrite(request.c_str()),
};
- StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
+ StaticSocketDataProvider data2(data_reads2, data_reads2_index,
data_writes2, arraysize(data_writes2));
mock_socket_factory_.AddSocketDataProvider(&data2);
// Expect that we get "content" and not "Bypass message", and that there's
// a "not-proxy" "Server:" header in the final response.
- ExecuteRequestExpectingContentAndHeader("content", "server", "not-proxy");
+ if (retry_expected) {
+ ExecuteRequestExpectingContentAndHeader(method, content,
+ "server", "not-proxy");
+ } else {
+ ExecuteRequestExpectingContentAndHeader(method, "Bypass message", "", "");
+ }
// We should also observe the bad proxy in the retry list.
TestBadProxies(1u, bad_proxy, "");
@@ -186,7 +213,8 @@ class HttpNetworkLayerTest : public PlatformTest {
// Expect that we get "content" and not "Bypass message", and that there's
// a "not-proxy" "Server:" header in the final response.
- ExecuteRequestExpectingContentAndHeader("content", "server", "not-proxy");
+ ExecuteRequestExpectingContentAndHeader("GET", "content",
+ "server", "not-proxy");
// We should also observe the bad proxy in the retry list.
TestBadProxies(1u, bad_proxy, "");
@@ -221,7 +249,7 @@ class HttpNetworkLayerTest : public PlatformTest {
mock_socket_factory_.AddSocketDataProvider(&data2);
// Expect that we get "Bypass message", and not "content"..
- ExecuteRequestExpectingContentAndHeader("Bypass message", "", "");
+ ExecuteRequestExpectingContentAndHeader("GET", "Bypass message", "", "");
// We should also observe the bad proxy or proxies in the retry list.
TestBadProxies(proxy_count, bad_proxy, bad_proxy2);
@@ -330,6 +358,67 @@ TEST_F(HttpNetworkLayerTest, ServerTwoProxyBypassFixed) {
TestProxyFallback(bad_proxy);
}
+TEST_F(HttpNetworkLayerTest, BypassAndRetryIdempotentMethods) {
+ std::string bad_proxy = GetChromeProxy();
+ const struct {
+ const char* method;
mef 2013/12/18 16:34:41 why is method const char* but content std::string?
bengr 2013/12/18 19:39:47 No good reason. Changed so both are std::string.
+ std::string content;
+ bool expected_to_retry;
+ } tests[] = {
+ {
+ "GET",
+ "content",
+ true,
+ },
+ {
+ "OPTIONS",
+ "content",
+ true,
+ },
+ {
+ "HEAD",
+ "",
+ true,
+ },
+ {
+ "PUT",
+ "",
+ true,
+ },
+ {
+ "DELETE",
+ "content",
+ true,
+ },
+ {
+ "TRACE",
+ "content",
+ true,
+ },
+ {
+ "POST",
+ "Bypass message",
+ false,
+ },
+ };
+
+ for (size_t i = 0; i < arraysize(tests); ++i) {
+ ConfigureTestDependencies(
+ ProxyService::CreateFixed(bad_proxy +", good:8080"));
+ MockRead data_reads[] = {
+ MockRead("HTTP/1.1 200 OK\r\n"
+ "Connection: proxy-bypass\r\n\r\n"),
+ MockRead("Bypass message"),
+ MockRead(SYNCHRONOUS, OK),
+ };
+ TestProxyFallbackByMethodWithMockReads(bad_proxy, data_reads,
+ arraysize(data_reads),
+ tests[i].method,
+ tests[i].content,
+ tests[i].expected_to_retry);
+ }
+}
+
TEST_F(HttpNetworkLayerTest, ServerOneProxyWithDirectBypassPac) {
std::string bad_proxy = GetChromeProxy();
ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult(
« no previous file with comments | « no previous file | net/http/http_network_transaction.cc » ('j') | net/http/http_network_transaction.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698