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

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 118316: Send the "Proxy-Connection: keep-alive" header with HTTP CONNECT... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <math.h> // ceil 5 #include <math.h> // ceil
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "net/base/client_socket_factory.h" 8 #include "net/base/client_socket_factory.h"
9 #include "net/base/completion_callback.h" 9 #include "net/base/completion_callback.h"
10 #include "net/base/socket_test_util.h" 10 #include "net/base/socket_test_util.h"
(...skipping 11 matching lines...) Expand all
22 22
23 //----------------------------------------------------------------------------- 23 //-----------------------------------------------------------------------------
24 24
25 namespace net { 25 namespace net {
26 26
27 // Create a proxy service which fails on all requests (falls back to direct). 27 // Create a proxy service which fails on all requests (falls back to direct).
28 ProxyService* CreateNullProxyService() { 28 ProxyService* CreateNullProxyService() {
29 return ProxyService::CreateNull(); 29 return ProxyService::CreateNull();
30 } 30 }
31 31
32 // Helper to manage the lifetimes of the dependencies for a HttpNetworkTransacti on. 32 // Helper to manage the lifetimes of the dependencies for a
33 // HttpNetworkTransaction.
33 class SessionDependencies { 34 class SessionDependencies {
34 public: 35 public:
35 // Default set of dependencies -- "null" proxy service. 36 // Default set of dependencies -- "null" proxy service.
36 SessionDependencies() : proxy_service(CreateNullProxyService()) {} 37 SessionDependencies() : proxy_service(CreateNullProxyService()) {}
37 38
38 // Custom proxy service dependency. 39 // Custom proxy service dependency.
39 SessionDependencies(ProxyService* proxy_service) 40 explicit SessionDependencies(ProxyService* proxy_service)
40 : proxy_service(proxy_service) {} 41 : proxy_service(proxy_service) {}
41 42
42 scoped_ptr<ProxyService> proxy_service; 43 scoped_ptr<ProxyService> proxy_service;
43 MockClientSocketFactory socket_factory; 44 MockClientSocketFactory socket_factory;
44 }; 45 };
45 46
46 ProxyService* CreateFixedProxyService(const std::string& proxy) { 47 ProxyService* CreateFixedProxyService(const std::string& proxy) {
47 net::ProxyConfig proxy_config; 48 net::ProxyConfig proxy_config;
48 proxy_config.proxy_rules.ParseFromString(proxy); 49 proxy_config.proxy_rules.ParseFromString(proxy);
49 return ProxyService::CreateFixed(proxy_config); 50 return ProxyService::CreateFixed(proxy_config);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 rv = ReadTransaction(trans.get(), &out.response_data); 109 rv = ReadTransaction(trans.get(), &out.response_data);
109 EXPECT_EQ(OK, rv); 110 EXPECT_EQ(OK, rv);
110 111
111 return out; 112 return out;
112 } 113 }
113 114
114 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, 115 void ConnectStatusHelperWithExpectedStatus(const MockRead& status,
115 int expected_status); 116 int expected_status);
116 117
117 void ConnectStatusHelper(const MockRead& status); 118 void ConnectStatusHelper(const MockRead& status);
118
119 }; 119 };
120 120
121 // Fill |str| with a long header list that consumes >= |size| bytes. 121 // Fill |str| with a long header list that consumes >= |size| bytes.
122 void FillLargeHeadersString(std::string* str, int size) { 122 void FillLargeHeadersString(std::string* str, int size) {
123 const char* row = 123 const char* row =
124 "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; 124 "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n";
125 const int sizeof_row = strlen(row); 125 const int sizeof_row = strlen(row);
126 const int num_rows = static_cast<int>( 126 const int num_rows = static_cast<int>(
127 ceil(static_cast<float>(size) / sizeof_row)); 127 ceil(static_cast<float>(size) / sizeof_row));
128 const int sizeof_data = num_rows * sizeof_row; 128 const int sizeof_data = num_rows * sizeof_row;
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 session.get(), &session_deps.socket_factory)); 946 session.get(), &session_deps.socket_factory));
947 947
948 HttpRequestInfo request; 948 HttpRequestInfo request;
949 request.method = "GET"; 949 request.method = "GET";
950 request.url = GURL("https://www.google.com/"); 950 request.url = GURL("https://www.google.com/");
951 request.load_flags = 0; 951 request.load_flags = 0;
952 952
953 // Since we have proxy, should try to establish tunnel. 953 // Since we have proxy, should try to establish tunnel.
954 MockWrite data_writes1[] = { 954 MockWrite data_writes1[] = {
955 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 955 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
956 "Host: www.google.com\r\n\r\n"), 956 "Host: www.google.com\r\n"
957 "Proxy-Connection: keep-alive\r\n\r\n"),
957 958
958 // After calling trans->RestartWithAuth(), this is the request we should 959 // After calling trans->RestartWithAuth(), this is the request we should
959 // be issuing -- the final header line contains the credentials. 960 // be issuing -- the final header line contains the credentials.
960 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 961 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
961 "Host: www.google.com\r\n" 962 "Host: www.google.com\r\n"
963 "Proxy-Connection: keep-alive\r\n"
962 "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), 964 "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"),
963 }; 965 };
964 966
965 // The proxy responds to the connect with a 407, using a persistent 967 // The proxy responds to the connect with a 407, using a persistent
966 // connection. 968 // connection.
967 MockRead data_reads1[] = { 969 MockRead data_reads1[] = {
968 // No credentials. 970 // No credentials.
969 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), 971 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
970 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 972 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
971 MockRead("Content-Length: 10\r\n\r\n"), 973 MockRead("Content-Length: 10\r\n\r\n"),
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm); 1033 EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm);
1032 EXPECT_EQ(L"basic", response->auth_challenge->scheme); 1034 EXPECT_EQ(L"basic", response->auth_challenge->scheme);
1033 } 1035 }
1034 1036
1035 // Test that we don't read the response body when we fail to establish a tunnel, 1037 // Test that we don't read the response body when we fail to establish a tunnel,
1036 // even if the user cancels the proxy's auth attempt. 1038 // even if the user cancels the proxy's auth attempt.
1037 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { 1039 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) {
1038 // Configure against proxy server "myproxy:70". 1040 // Configure against proxy server "myproxy:70".
1039 SessionDependencies session_deps(CreateFixedProxyService("myproxy:70")); 1041 SessionDependencies session_deps(CreateFixedProxyService("myproxy:70"));
1040 1042
1041 scoped_refptr<HttpNetworkSession> session( CreateSession(&session_deps)); 1043 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1042 1044
1043 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( 1045 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(
1044 session.get(), &session_deps.socket_factory)); 1046 session.get(), &session_deps.socket_factory));
1045 1047
1046 HttpRequestInfo request; 1048 HttpRequestInfo request;
1047 request.method = "GET"; 1049 request.method = "GET";
1048 request.url = GURL("https://www.google.com/"); 1050 request.url = GURL("https://www.google.com/");
1049 request.load_flags = 0; 1051 request.load_flags = 0;
1050 1052
1051 // Since we have proxy, should try to establish tunnel. 1053 // Since we have proxy, should try to establish tunnel.
1052 MockWrite data_writes[] = { 1054 MockWrite data_writes[] = {
1053 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 1055 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1054 "Host: www.google.com\r\n\r\n"), 1056 "Host: www.google.com\r\n"
1057 "Proxy-Connection: keep-alive\r\n\r\n"),
1055 }; 1058 };
1056 1059
1057 // The proxy responds to the connect with a 407. 1060 // The proxy responds to the connect with a 407.
1058 MockRead data_reads[] = { 1061 MockRead data_reads[] = {
1059 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), 1062 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
1060 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 1063 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
1061 MockRead("Content-Length: 10\r\n\r\n"), 1064 MockRead("Content-Length: 10\r\n\r\n"),
1062 MockRead(false, ERR_UNEXPECTED), // Should not be reached. 1065 MockRead(false, ERR_UNEXPECTED), // Should not be reached.
1063 }; 1066 };
1064 1067
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 session.get(), &session_deps.socket_factory)); 1102 session.get(), &session_deps.socket_factory));
1100 1103
1101 HttpRequestInfo request; 1104 HttpRequestInfo request;
1102 request.method = "GET"; 1105 request.method = "GET";
1103 request.url = GURL("https://www.google.com/"); 1106 request.url = GURL("https://www.google.com/");
1104 request.load_flags = 0; 1107 request.load_flags = 0;
1105 1108
1106 // Since we have proxy, should try to establish tunnel. 1109 // Since we have proxy, should try to establish tunnel.
1107 MockWrite data_writes[] = { 1110 MockWrite data_writes[] = {
1108 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 1111 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1109 "Host: www.google.com\r\n\r\n"), 1112 "Host: www.google.com\r\n"
1113 "Proxy-Connection: keep-alive\r\n\r\n"),
1110 }; 1114 };
1111 1115
1112 MockRead data_reads[] = { 1116 MockRead data_reads[] = {
1113 status, 1117 status,
1114 MockRead("Content-Length: 10\r\n\r\n"), 1118 MockRead("Content-Length: 10\r\n\r\n"),
1115 // No response body because the test stops reading here. 1119 // No response body because the test stops reading here.
1116 MockRead(false, ERR_UNEXPECTED), // Should not be reached. 1120 MockRead(false, ERR_UNEXPECTED), // Should not be reached.
1117 }; 1121 };
1118 1122
1119 MockSocket data; 1123 MockSocket data;
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
1827 session.get(), &session_deps.socket_factory)); 1831 session.get(), &session_deps.socket_factory));
1828 1832
1829 HttpRequestInfo request; 1833 HttpRequestInfo request;
1830 request.method = "GET"; 1834 request.method = "GET";
1831 request.url = GURL("https://www.google.com/"); 1835 request.url = GURL("https://www.google.com/");
1832 request.load_flags = 0; 1836 request.load_flags = 0;
1833 1837
1834 // Since we have proxy, should try to establish tunnel. 1838 // Since we have proxy, should try to establish tunnel.
1835 MockWrite data_writes1[] = { 1839 MockWrite data_writes1[] = {
1836 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 1840 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1837 "Host: www.google.com\r\n\r\n"), 1841 "Host: www.google.com\r\n"
1842 "Proxy-Connection: keep-alive\r\n\r\n"),
1838 }; 1843 };
1839 1844
1840 // The proxy responds to the connect with a 404, using a persistent 1845 // The proxy responds to the connect with a 404, using a persistent
1841 // connection. Usually a proxy would return 501 (not implemented), 1846 // connection. Usually a proxy would return 501 (not implemented),
1842 // or 200 (tunnel established). 1847 // or 200 (tunnel established).
1843 MockRead data_reads1[] = { 1848 MockRead data_reads1[] = {
1844 MockRead("HTTP/1.1 404 Not Found\r\n"), 1849 MockRead("HTTP/1.1 404 Not Found\r\n"),
1845 MockRead("Content-Length: 10\r\n\r\n"), 1850 MockRead("Content-Length: 10\r\n\r\n"),
1846 MockRead(false, ERR_UNEXPECTED), // Should not be reached. 1851 MockRead(false, ERR_UNEXPECTED), // Should not be reached.
1847 }; 1852 };
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
2689 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { 2694 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) {
2690 SessionDependencies session_deps(CreateFixedProxyService("myproxy:70")); 2695 SessionDependencies session_deps(CreateFixedProxyService("myproxy:70"));
2691 2696
2692 HttpRequestInfo request; 2697 HttpRequestInfo request;
2693 request.method = "GET"; 2698 request.method = "GET";
2694 request.url = GURL("https://www.google.com/"); 2699 request.url = GURL("https://www.google.com/");
2695 request.load_flags = 0; 2700 request.load_flags = 0;
2696 2701
2697 MockWrite proxy_writes[] = { 2702 MockWrite proxy_writes[] = {
2698 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 2703 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2699 "Host: www.google.com\r\n\r\n"), 2704 "Host: www.google.com\r\n"
2705 "Proxy-Connection: keep-alive\r\n\r\n"),
2700 }; 2706 };
2701 2707
2702 MockRead proxy_reads[] = { 2708 MockRead proxy_reads[] = {
2703 MockRead("HTTP/1.0 200 Connected\r\n\r\n"), 2709 MockRead("HTTP/1.0 200 Connected\r\n\r\n"),
2704 MockRead(false, OK) 2710 MockRead(false, OK)
2705 }; 2711 };
2706 2712
2707 MockWrite data_writes[] = { 2713 MockWrite data_writes[] = {
2708 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 2714 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2709 "Host: www.google.com\r\n\r\n"), 2715 "Host: www.google.com\r\n"
2716 "Proxy-Connection: keep-alive\r\n\r\n"),
2710 MockWrite("GET / HTTP/1.1\r\n" 2717 MockWrite("GET / HTTP/1.1\r\n"
2711 "Host: www.google.com\r\n" 2718 "Host: www.google.com\r\n"
2712 "Connection: keep-alive\r\n\r\n"), 2719 "Connection: keep-alive\r\n\r\n"),
2713 }; 2720 };
2714 2721
2715 MockRead data_reads[] = { 2722 MockRead data_reads[] = {
2716 MockRead("HTTP/1.0 200 Connected\r\n\r\n"), 2723 MockRead("HTTP/1.0 200 Connected\r\n\r\n"),
2717 MockRead("HTTP/1.0 200 OK\r\n"), 2724 MockRead("HTTP/1.0 200 OK\r\n"),
2718 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), 2725 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
2719 MockRead("Content-Length: 100\r\n\r\n"), 2726 MockRead("Content-Length: 100\r\n\r\n"),
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
3081 TestCompletionCallback callback; 3088 TestCompletionCallback callback;
3082 3089
3083 int rv = trans->Start(&request, &callback); 3090 int rv = trans->Start(&request, &callback);
3084 EXPECT_EQ(ERR_IO_PENDING, rv); 3091 EXPECT_EQ(ERR_IO_PENDING, rv);
3085 3092
3086 rv = callback.WaitForResult(); 3093 rv = callback.WaitForResult();
3087 EXPECT_EQ(OK, rv); 3094 EXPECT_EQ(OK, rv);
3088 } 3095 }
3089 3096
3090 } // namespace net 3097 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698