| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/http/http_stream_factory_impl.h" | 5 #include "net/http/http_stream_factory_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "net/base/capturing_net_log.h" |
| 12 #include "net/base/net_log.h" | 13 #include "net/base/net_log.h" |
| 13 #include "net/base/test_completion_callback.h" | 14 #include "net/base/test_completion_callback.h" |
| 14 #include "net/cert/mock_cert_verifier.h" | 15 #include "net/cert/mock_cert_verifier.h" |
| 15 #include "net/dns/mock_host_resolver.h" | 16 #include "net/dns/mock_host_resolver.h" |
| 16 #include "net/http/http_auth_handler_factory.h" | 17 #include "net/http/http_auth_handler_factory.h" |
| 17 #include "net/http/http_network_session.h" | 18 #include "net/http/http_network_session.h" |
| 18 #include "net/http/http_network_session_peer.h" | 19 #include "net/http/http_network_session_peer.h" |
| 19 #include "net/http/http_network_transaction.h" | 20 #include "net/http/http_network_transaction.h" |
| 20 #include "net/http/http_request_info.h" | 21 #include "net/http/http_request_info.h" |
| 21 #include "net/http/http_server_properties.h" | 22 #include "net/http/http_server_properties.h" |
| 22 #include "net/http/http_server_properties_impl.h" | 23 #include "net/http/http_server_properties_impl.h" |
| 23 #include "net/http/http_stream.h" | 24 #include "net/http/http_stream.h" |
| 24 #include "net/http/transport_security_state.h" | 25 #include "net/http/transport_security_state.h" |
| 25 #include "net/proxy/proxy_info.h" | 26 #include "net/proxy/proxy_info.h" |
| 26 #include "net/proxy/proxy_service.h" | 27 #include "net/proxy/proxy_service.h" |
| 28 #include "net/quic/test_tools/mock_clock.h" |
| 29 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" |
| 30 #include "net/quic/test_tools/mock_random.h" |
| 27 #include "net/socket/client_socket_handle.h" | 31 #include "net/socket/client_socket_handle.h" |
| 28 #include "net/socket/mock_client_socket_pool_manager.h" | 32 #include "net/socket/mock_client_socket_pool_manager.h" |
| 29 #include "net/socket/next_proto.h" | 33 #include "net/socket/next_proto.h" |
| 30 #include "net/socket/socket_test_util.h" | 34 #include "net/socket/socket_test_util.h" |
| 31 #include "net/spdy/spdy_session.h" | 35 #include "net/spdy/spdy_session.h" |
| 32 #include "net/spdy/spdy_session_pool.h" | 36 #include "net/spdy/spdy_session_pool.h" |
| 33 #include "net/spdy/spdy_test_util_common.h" | 37 #include "net/spdy/spdy_test_util_common.h" |
| 34 #include "net/ssl/ssl_config_service.h" | 38 #include "net/ssl/ssl_config_service.h" |
| 35 #include "net/ssl/ssl_config_service_defaults.h" | 39 #include "net/ssl/ssl_config_service_defaults.h" |
| 36 // This file can be included from net/http even though | 40 // This file can be included from net/http even though |
| (...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 HostPortPair("myproxy", 8888)))); | 1105 HostPortPair("myproxy", 8888)))); |
| 1102 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetSocketPoolForHTTPProxy( | 1106 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetSocketPoolForHTTPProxy( |
| 1103 HttpNetworkSession::WEBSOCKET_SOCKET_POOL, | 1107 HttpNetworkSession::WEBSOCKET_SOCKET_POOL, |
| 1104 HostPortPair("myproxy", 8888)))); | 1108 HostPortPair("myproxy", 8888)))); |
| 1105 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSocketPoolForSSLWithProxy( | 1109 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSocketPoolForSSLWithProxy( |
| 1106 HttpNetworkSession::WEBSOCKET_SOCKET_POOL, | 1110 HttpNetworkSession::WEBSOCKET_SOCKET_POOL, |
| 1107 HostPortPair("myproxy", 8888)))); | 1111 HostPortPair("myproxy", 8888)))); |
| 1108 EXPECT_FALSE(waiter.used_proxy_info().is_direct()); | 1112 EXPECT_FALSE(waiter.used_proxy_info().is_direct()); |
| 1109 } | 1113 } |
| 1110 | 1114 |
| 1115 TEST_P(HttpStreamFactoryTest, RequestQuicHTTPStream) { |
| 1116 for (int i = 0; i <= 1; i++) { |
| 1117 scoped_ptr<ProxyService> proxy_service; |
| 1118 proxy_service.reset(ProxyService::CreateFixedFromPacResult("DIRECT")); |
| 1119 |
| 1120 HttpNetworkSession::Params params; |
| 1121 MockClock* clock_ = new MockClock(); |
| 1122 MockRandom random_generator_; |
| 1123 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
| 1124 MockCertVerifier cert_verifier_; |
| 1125 |
| 1126 params.enable_quic = true; |
| 1127 params.enable_quic_for_proxies = true; |
| 1128 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service( |
| 1129 new SSLConfigServiceDefaults); |
| 1130 HttpServerPropertiesImpl http_server_properties; |
| 1131 MockClientSocketFactory socket_factory; |
| 1132 params.client_socket_factory = &socket_factory; |
| 1133 MockHostResolver host_resolver; |
| 1134 params.host_resolver = &host_resolver; |
| 1135 TransportSecurityState transport_security_state; |
| 1136 params.transport_security_state = &transport_security_state; |
| 1137 params.proxy_service = proxy_service.get(); |
| 1138 params.ssl_config_service = ssl_config_service.get(); |
| 1139 params.http_server_properties = http_server_properties.GetWeakPtr(); |
| 1140 params.use_alternate_protocols = true; |
| 1141 params.next_protos = NextProtosWithSpdyAndQuic(true, true); |
| 1142 params.quic_clock = clock_; |
| 1143 clock_->AdvanceTime(QuicTime::Delta::FromMilliseconds(20)); |
| 1144 params.quic_random = &random_generator_; |
| 1145 params.quic_crypto_client_stream_factory = &crypto_client_stream_factory_; |
| 1146 params.cert_verifier = &cert_verifier_; |
| 1147 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; |
| 1148 params.http_auth_handler_factory = auth_handler_factory_.get(); |
| 1149 params.quic_supported_versions.push_back(QUIC_VERSION_24); |
| 1150 |
| 1151 params.origin_to_force_quic_on = |
| 1152 HostPortPair::FromString("www.google.com:80"); |
| 1153 |
| 1154 scoped_refptr<HttpNetworkSession> session; |
| 1155 session = new HttpNetworkSession(params); |
| 1156 session->quic_stream_factory()->set_require_confirmation(false); |
| 1157 |
| 1158 MockRead http_reads[] = { |
| 1159 MockRead("HTTP/1.1 200 OK\r\n"), |
| 1160 MockRead("Alternate-Protocol: 80:quic\r\n\r\n"), |
| 1161 MockRead("hello world"), |
| 1162 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1163 MockRead(ASYNC, OK), |
| 1164 }; |
| 1165 |
| 1166 HttpRequestInfo request_info; |
| 1167 request_info.method = "GET"; |
| 1168 request_info.url = GURL("http://www.google.com"); |
| 1169 |
| 1170 request_info.load_flags = 0; |
| 1171 if (i == 1) { |
| 1172 request_info.load_flags = LOAD_UNENCRYPTED_HTTP11; |
| 1173 } |
| 1174 |
| 1175 SSLConfig ssl_config; |
| 1176 EXPECT_TRUE(params.enable_quic) << i; |
| 1177 |
| 1178 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 1179 nullptr, 0); |
| 1180 socket_factory.AddSocketDataProvider(&http_data); |
| 1181 |
| 1182 scoped_ptr<HttpNetworkTransaction> trans( |
| 1183 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1184 |
| 1185 CapturingBoundNetLog net_log_; |
| 1186 TestCompletionCallback callback; |
| 1187 |
| 1188 int rv = trans.get()->Start(&request_info, callback.callback(), |
| 1189 net_log_.bound()); |
| 1190 EXPECT_EQ(ERR_IO_PENDING, rv) << i; |
| 1191 EXPECT_EQ(i == 0, OK != callback.WaitForResult()); |
| 1192 |
| 1193 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1194 EXPECT_EQ(i == 0, response == nullptr) << i; |
| 1195 if (i == 0) { |
| 1196 // When LOAD_UNENCRYPTED_HTTP11 is not enabled, request fails because |
| 1197 // there is no QUIC mock socket. |
| 1198 continue; |
| 1199 } |
| 1200 ASSERT_TRUE(response->headers.get() != nullptr) << i; |
| 1201 EXPECT_FALSE(response->was_fetched_via_spdy) << i; |
| 1202 EXPECT_FALSE(response->was_npn_negotiated) << i; |
| 1203 |
| 1204 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, |
| 1205 response->connection_info) |
| 1206 << i; |
| 1207 |
| 1208 EXPECT_EQ(i == 1, http_server_properties.RequiresHTTP11( |
| 1209 HostPortPair::FromString("www.google.com:80"))) |
| 1210 << i; |
| 1211 } |
| 1212 } |
| 1213 |
| 1111 TEST_P(HttpStreamFactoryTest, RequestSpdyHttpStream) { | 1214 TEST_P(HttpStreamFactoryTest, RequestSpdyHttpStream) { |
| 1112 SpdySessionDependencies session_deps(GetParam(), | 1215 for (int i = 0; i <= 1; i++) { |
| 1113 ProxyService::CreateDirect()); | 1216 SpdySessionDependencies session_deps(GetParam(), |
| 1217 ProxyService::CreateDirect()); |
| 1114 | 1218 |
| 1115 MockRead mock_read(ASYNC, OK); | 1219 MockRead mock_read(ASYNC, OK); |
| 1116 DeterministicSocketData socket_data(&mock_read, 1, nullptr, 0); | 1220 DeterministicSocketData socket_data(&mock_read, 1, nullptr, 0); |
| 1117 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | 1221 socket_data.set_connect_data(MockConnect(ASYNC, OK)); |
| 1118 session_deps.deterministic_socket_factory->AddSocketDataProvider( | 1222 session_deps.deterministic_socket_factory->AddSocketDataProvider( |
| 1119 &socket_data); | 1223 &socket_data); |
| 1120 | 1224 |
| 1121 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | 1225 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); |
| 1122 ssl_socket_data.SetNextProto(GetParam()); | 1226 ssl_socket_data.SetNextProto(GetParam()); |
| 1123 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider( | 1227 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider( |
| 1124 &ssl_socket_data); | 1228 &ssl_socket_data); |
| 1125 | 1229 |
| 1126 HostPortPair host_port_pair("www.google.com", 443); | 1230 HostPortPair host_port_pair("www.google.com", 443); |
| 1127 scoped_refptr<HttpNetworkSession> | 1231 scoped_refptr<HttpNetworkSession> session( |
| 1128 session(SpdySessionDependencies::SpdyCreateSessionDeterministic( | 1232 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps)); |
| 1129 &session_deps)); | |
| 1130 | 1233 |
| 1131 // Now request a stream. | 1234 // Now request a stream. |
| 1132 HttpRequestInfo request_info; | 1235 HttpRequestInfo request_info; |
| 1133 request_info.method = "GET"; | 1236 request_info.method = "GET"; |
| 1134 request_info.url = GURL("https://www.google.com"); | 1237 request_info.url = GURL("https://www.google.com"); |
| 1135 request_info.load_flags = 0; | 1238 request_info.load_flags = 0; |
| 1239 if (i == 1) { |
| 1240 request_info.load_flags = LOAD_UNENCRYPTED_HTTP11; |
| 1241 } |
| 1136 | 1242 |
| 1137 SSLConfig ssl_config; | 1243 SSLConfig ssl_config; |
| 1138 StreamRequestWaiter waiter; | 1244 StreamRequestWaiter waiter; |
| 1139 scoped_ptr<HttpStreamRequest> request( | 1245 scoped_ptr<HttpStreamRequest> request( |
| 1140 session->http_stream_factory()->RequestStream( | 1246 session->http_stream_factory()->RequestStream( |
| 1141 request_info, | 1247 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, &waiter, |
| 1142 DEFAULT_PRIORITY, | 1248 BoundNetLog())); |
| 1143 ssl_config, | 1249 waiter.WaitForStream(); |
| 1144 ssl_config, | 1250 EXPECT_TRUE(waiter.stream_done()); |
| 1145 &waiter, | 1251 EXPECT_TRUE(nullptr == waiter.websocket_stream()); |
| 1146 BoundNetLog())); | 1252 ASSERT_TRUE(nullptr != waiter.stream()); |
| 1147 waiter.WaitForStream(); | 1253 EXPECT_EQ(i == 0, waiter.stream()->IsSpdyHttpStream()); |
| 1148 EXPECT_TRUE(waiter.stream_done()); | 1254 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetTransportSocketPool( |
| 1149 EXPECT_TRUE(nullptr == waiter.websocket_stream()); | 1255 HttpNetworkSession::NORMAL_SOCKET_POOL))); |
| 1150 ASSERT_TRUE(nullptr != waiter.stream()); | 1256 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetSSLSocketPool( |
| 1151 EXPECT_TRUE(waiter.stream()->IsSpdyHttpStream()); | 1257 HttpNetworkSession::NORMAL_SOCKET_POOL))); |
| 1152 EXPECT_EQ(1, GetSocketPoolGroupCount( | 1258 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetTransportSocketPool( |
| 1153 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | 1259 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); |
| 1154 EXPECT_EQ(1, GetSocketPoolGroupCount( | 1260 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSSLSocketPool( |
| 1155 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | 1261 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); |
| 1156 EXPECT_EQ(0, GetSocketPoolGroupCount( | 1262 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); |
| 1157 session->GetTransportSocketPool( | 1263 |
| 1158 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); | 1264 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 1159 EXPECT_EQ(0, GetSocketPoolGroupCount( | 1265 session->http_server_properties(); |
| 1160 session->GetSSLSocketPool(HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); | 1266 |
| 1161 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | 1267 EXPECT_EQ(i == 1, http_server_properties->RequiresHTTP11(host_port_pair)) |
| 1268 << i; |
| 1269 } |
| 1162 } | 1270 } |
| 1163 | 1271 |
| 1164 // TODO(ricea): This test can be removed once the new WebSocket stack supports | 1272 // TODO(ricea): This test can be removed once the new WebSocket stack supports |
| 1165 // SPDY. Currently, even if we connect to a SPDY-supporting server, we need to | 1273 // SPDY. Currently, even if we connect to a SPDY-supporting server, we need to |
| 1166 // use plain SSL. | 1274 // use plain SSL. |
| 1167 TEST_P(HttpStreamFactoryTest, RequestWebSocketSpdyHandshakeStreamButGetSSL) { | 1275 TEST_P(HttpStreamFactoryTest, RequestWebSocketSpdyHandshakeStreamButGetSSL) { |
| 1168 SpdySessionDependencies session_deps(GetParam(), | 1276 SpdySessionDependencies session_deps(GetParam(), |
| 1169 ProxyService::CreateDirect()); | 1277 ProxyService::CreateDirect()); |
| 1170 | 1278 |
| 1171 MockRead mock_read(SYNCHRONOUS, ERR_IO_PENDING); | 1279 MockRead mock_read(SYNCHRONOUS, ERR_IO_PENDING); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | 1468 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); |
| 1361 | 1469 |
| 1362 // Make sure there is no orphaned job. it is already canceled. | 1470 // Make sure there is no orphaned job. it is already canceled. |
| 1363 ASSERT_EQ(0u, static_cast<HttpStreamFactoryImpl*>( | 1471 ASSERT_EQ(0u, static_cast<HttpStreamFactoryImpl*>( |
| 1364 session->http_stream_factory_for_websocket())->num_orphaned_jobs()); | 1472 session->http_stream_factory_for_websocket())->num_orphaned_jobs()); |
| 1365 } | 1473 } |
| 1366 | 1474 |
| 1367 } // namespace | 1475 } // namespace |
| 1368 | 1476 |
| 1369 } // namespace net | 1477 } // namespace net |
| OLD | NEW |