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

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: Using ARRAYSIZE_UNSAFE in test 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') | no next file with comments »
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 174ae2e7956c447ccbd18483e5d89ed3d21169bf..2c949d01b3df2e4656c64465536fd7097c62e595 100644
--- a/net/http/http_network_layer_unittest.cc
+++ b/net/http/http_network_layer_unittest.cc
@@ -4,6 +4,7 @@
#include "net/http/http_network_layer.h"
+#include "base/basictypes.h"
#include "base/strings/stringprintf.h"
#include "net/base/net_log.h"
#include "net/cert/mock_cert_verifier.h"
@@ -60,14 +61,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;
@@ -122,10 +124,31 @@ class HttpNetworkLayerTest : public PlatformTest {
MockRead data_reads[],
int data_reads_size,
unsigned int expected_retry_info_size) {
+ TestProxyFallbackByMethodWithMockReads(bad_proxy, bad_proxy2, data_reads,
+ data_reads_size, "GET", "content",
+ true, expected_retry_info_size);
+ }
+
+ void TestProxyFallbackByMethodWithMockReads(
+ const std::string& bad_proxy,
+ const std::string& bad_proxy2,
+ MockRead data_reads[],
+ int data_reads_size,
+ std::string method,
+ std::string content,
+ bool retry_expected,
+ unsigned int expected_retry_info_size) {
+ 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,
@@ -133,24 +156,29 @@ 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(expected_retry_info_size, bad_proxy, bad_proxy2);
@@ -194,7 +222,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, "");
@@ -229,7 +258,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);
@@ -338,6 +367,67 @@ TEST_F(HttpNetworkLayerTest, ServerTwoProxyBypassFixed) {
TestProxyFallback(bad_proxy);
}
+TEST_F(HttpNetworkLayerTest, BypassAndRetryIdempotentMethods) {
+ std::string bad_proxy = GetChromeProxy();
+ const struct {
+ std::string method;
+ 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_UNSAFE(tests); ++i) {
+ ConfigureTestDependencies(
+ ProxyService::CreateFixed(bad_proxy +", good:8080"));
+ MockRead data_reads[] = {
+ MockRead("HTTP/1.1 200 OK\r\n"
+ "Chrome-Proxy: bypass=0\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, 1u);
+ }
+}
+
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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698