| Index: net/http/http_network_transaction_unittest.cc
|
| ===================================================================
|
| --- net/http/http_network_transaction_unittest.cc (revision 57023)
|
| +++ net/http/http_network_transaction_unittest.cc (working copy)
|
| @@ -2494,6 +2494,160 @@
|
| EXPECT_EQ(1, session->tcp_socket_pool()->IdleSocketCount());
|
| }
|
|
|
| +// Make sure that we recycle a SSL socket after reading all of the response
|
| +// body.
|
| +TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) {
|
| + SessionDependencies session_deps;
|
| + HttpRequestInfo request;
|
| + request.method = "GET";
|
| + request.url = GURL("https://www.google.com/");
|
| + request.load_flags = 0;
|
| +
|
| + MockWrite data_writes[] = {
|
| + MockWrite("GET / HTTP/1.1\r\n"
|
| + "Host: www.google.com\r\n"
|
| + "Connection: keep-alive\r\n\r\n"),
|
| + };
|
| +
|
| + MockRead data_reads[] = {
|
| + MockRead("HTTP/1.1 200 OK\r\n"),
|
| + MockRead("Content-Length: 11\r\n\r\n"),
|
| + MockRead("hello world"),
|
| + MockRead(false, OK),
|
| + };
|
| +
|
| + SSLSocketDataProvider ssl(true, OK);
|
| + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
|
| +
|
| + StaticSocketDataProvider data(data_reads, arraysize(data_reads),
|
| + data_writes, arraysize(data_writes));
|
| + session_deps.socket_factory.AddSocketDataProvider(&data);
|
| +
|
| + TestCompletionCallback callback;
|
| +
|
| + scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
|
| + scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
|
| +
|
| + int rv = trans->Start(&request, &callback, BoundNetLog());
|
| +
|
| + EXPECT_EQ(ERR_IO_PENDING, rv);
|
| + EXPECT_EQ(OK, callback.WaitForResult());
|
| +
|
| + const HttpResponseInfo* response = trans->GetResponseInfo();
|
| + ASSERT_TRUE(response != NULL);
|
| + ASSERT_TRUE(response->headers != NULL);
|
| + EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
|
| +
|
| + EXPECT_EQ(0, session->tcp_socket_pool()->IdleSocketCount());
|
| +
|
| + std::string response_data;
|
| + rv = ReadTransaction(trans.get(), &response_data);
|
| + EXPECT_EQ(OK, rv);
|
| + EXPECT_EQ("hello world", response_data);
|
| +
|
| + // Empty the current queue. This is necessary because idle sockets are
|
| + // added to the connection pool asynchronously with a PostTask.
|
| + MessageLoop::current()->RunAllPending();
|
| +
|
| + // We now check to make sure the socket was added back to the pool.
|
| + EXPECT_EQ(1, session->ssl_socket_pool()->IdleSocketCount());
|
| +}
|
| +
|
| +// Grab a SSL socket, use it, and put it back into the pool. Then, reuse it
|
| +// from the pool and make sure that we recover okay.
|
| +TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) {
|
| + SessionDependencies session_deps;
|
| + HttpRequestInfo request;
|
| + request.method = "GET";
|
| + request.url = GURL("https://www.google.com/");
|
| + request.load_flags = 0;
|
| +
|
| + MockWrite data_writes[] = {
|
| + MockWrite("GET / HTTP/1.1\r\n"
|
| + "Host: www.google.com\r\n"
|
| + "Connection: keep-alive\r\n\r\n"),
|
| + MockWrite("GET / HTTP/1.1\r\n"
|
| + "Host: www.google.com\r\n"
|
| + "Connection: keep-alive\r\n\r\n"),
|
| + };
|
| +
|
| + MockRead data_reads[] = {
|
| + MockRead("HTTP/1.1 200 OK\r\n"),
|
| + MockRead("Content-Length: 11\r\n\r\n"),
|
| + MockRead(false, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
|
| + MockRead("hello world"),
|
| + MockRead(true, 0, 0) // EOF
|
| + };
|
| +
|
| + SSLSocketDataProvider ssl(true, OK);
|
| + SSLSocketDataProvider ssl2(true, OK);
|
| + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
|
| + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl2);
|
| +
|
| + StaticSocketDataProvider data(data_reads, arraysize(data_reads),
|
| + data_writes, arraysize(data_writes));
|
| + StaticSocketDataProvider data2(data_reads, arraysize(data_reads),
|
| + data_writes, arraysize(data_writes));
|
| + session_deps.socket_factory.AddSocketDataProvider(&data);
|
| + session_deps.socket_factory.AddSocketDataProvider(&data2);
|
| +
|
| + TestCompletionCallback callback;
|
| +
|
| + scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
|
| + scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
|
| +
|
| + int rv = trans->Start(&request, &callback, BoundNetLog());
|
| +
|
| + EXPECT_EQ(ERR_IO_PENDING, rv);
|
| + EXPECT_EQ(OK, callback.WaitForResult());
|
| +
|
| + const HttpResponseInfo* response = trans->GetResponseInfo();
|
| + ASSERT_TRUE(response != NULL);
|
| + ASSERT_TRUE(response->headers != NULL);
|
| + EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
|
| +
|
| + EXPECT_EQ(0, session->tcp_socket_pool()->IdleSocketCount());
|
| +
|
| + std::string response_data;
|
| + rv = ReadTransaction(trans.get(), &response_data);
|
| + EXPECT_EQ(OK, rv);
|
| + EXPECT_EQ("hello world", response_data);
|
| +
|
| + // Empty the current queue. This is necessary because idle sockets are
|
| + // added to the connection pool asynchronously with a PostTask.
|
| + MessageLoop::current()->RunAllPending();
|
| +
|
| + // We now check to make sure the socket was added back to the pool.
|
| + EXPECT_EQ(1, session->ssl_socket_pool()->IdleSocketCount());
|
| +
|
| + // Now start the second transaction, which should reuse the previous socket.
|
| +
|
| + trans.reset(new HttpNetworkTransaction(session));
|
| +
|
| + rv = trans->Start(&request, &callback, BoundNetLog());
|
| +
|
| + EXPECT_EQ(ERR_IO_PENDING, rv);
|
| + EXPECT_EQ(OK, callback.WaitForResult());
|
| +
|
| + response = trans->GetResponseInfo();
|
| + ASSERT_TRUE(response != NULL);
|
| + ASSERT_TRUE(response->headers != NULL);
|
| + EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
|
| +
|
| + EXPECT_EQ(0, session->tcp_socket_pool()->IdleSocketCount());
|
| +
|
| + rv = ReadTransaction(trans.get(), &response_data);
|
| + EXPECT_EQ(OK, rv);
|
| + EXPECT_EQ("hello world", response_data);
|
| +
|
| + // Empty the current queue. This is necessary because idle sockets are
|
| + // added to the connection pool asynchronously with a PostTask.
|
| + MessageLoop::current()->RunAllPending();
|
| +
|
| + // We now check to make sure the socket was added back to the pool.
|
| + EXPECT_EQ(1, session->ssl_socket_pool()->IdleSocketCount());
|
| +}
|
| +
|
| // Make sure that we recycle a socket after a zero-length response.
|
| // http://crbug.com/9880
|
| TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) {
|
| @@ -6595,4 +6749,169 @@
|
| MessageLoop::current()->RunAllPending();
|
| }
|
|
|
| +// Test a basic GET request through a proxy.
|
| +TEST_F(HttpNetworkTransactionTest, ProxyGet) {
|
| + SessionDependencies session_deps(CreateFixedProxyService("myproxy:70"));
|
| + CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
|
| + session_deps.net_log = log.bound().net_log();
|
| + scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
|
| +
|
| + scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
|
| +
|
| + HttpRequestInfo request;
|
| + request.method = "GET";
|
| + request.url = GURL("http://www.google.com/");
|
| +
|
| + MockWrite data_writes1[] = {
|
| + 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"),
|
| + };
|
| +
|
| + MockRead data_reads1[] = {
|
| + MockRead("HTTP/1.1 200 OK\r\n"),
|
| + MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
|
| + MockRead("Content-Length: 100\r\n\r\n"),
|
| + MockRead(false, OK),
|
| + };
|
| +
|
| + StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
|
| + data_writes1, arraysize(data_writes1));
|
| + session_deps.socket_factory.AddSocketDataProvider(&data1);
|
| +
|
| + TestCompletionCallback callback1;
|
| +
|
| + int rv = trans->Start(&request, &callback1, log.bound());
|
| + EXPECT_EQ(ERR_IO_PENDING, rv);
|
| +
|
| + rv = callback1.WaitForResult();
|
| + EXPECT_EQ(OK, rv);
|
| +
|
| + const HttpResponseInfo* response = trans->GetResponseInfo();
|
| + ASSERT_FALSE(response == NULL);
|
| +
|
| + EXPECT_TRUE(response->headers->IsKeepAlive());
|
| + EXPECT_EQ(200, response->headers->response_code());
|
| + EXPECT_EQ(100, response->headers->GetContentLength());
|
| + EXPECT_TRUE(response->was_fetched_via_proxy);
|
| + EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
|
| +}
|
| +
|
| +// Test a basic HTTPS GET request through a proxy.
|
| +TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) {
|
| + SessionDependencies session_deps(CreateFixedProxyService("myproxy:70"));
|
| + CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
|
| + session_deps.net_log = log.bound().net_log();
|
| + scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
|
| +
|
| + scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
|
| +
|
| + HttpRequestInfo request;
|
| + request.method = "GET";
|
| + request.url = GURL("https://www.google.com/");
|
| +
|
| + // Since we have proxy, should try to establish tunnel.
|
| + MockWrite data_writes1[] = {
|
| + MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
|
| + "Host: www.google.com\r\n"
|
| + "Proxy-Connection: keep-alive\r\n\r\n"),
|
| +
|
| + MockWrite("GET / HTTP/1.1\r\n"
|
| + "Host: www.google.com\r\n"
|
| + "Connection: keep-alive\r\n\r\n"),
|
| + };
|
| +
|
| + MockRead data_reads1[] = {
|
| + MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
|
| +
|
| + MockRead("HTTP/1.1 200 OK\r\n"),
|
| + MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
|
| + MockRead("Content-Length: 100\r\n\r\n"),
|
| + MockRead(false, OK),
|
| + };
|
| +
|
| + StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
|
| + data_writes1, arraysize(data_writes1));
|
| + session_deps.socket_factory.AddSocketDataProvider(&data1);
|
| + SSLSocketDataProvider ssl(true, OK);
|
| + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
|
| +
|
| + TestCompletionCallback callback1;
|
| +
|
| + int rv = trans->Start(&request, &callback1, log.bound());
|
| + EXPECT_EQ(ERR_IO_PENDING, rv);
|
| +
|
| + rv = callback1.WaitForResult();
|
| + EXPECT_EQ(OK, rv);
|
| + size_t pos = ExpectLogContainsSomewhere(
|
| + log.entries(), 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
|
| + NetLog::PHASE_NONE);
|
| + ExpectLogContainsSomewhere(
|
| + log.entries(), pos,
|
| + NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
|
| + NetLog::PHASE_NONE);
|
| +
|
| + const HttpResponseInfo* response = trans->GetResponseInfo();
|
| + ASSERT_FALSE(response == NULL);
|
| +
|
| + EXPECT_TRUE(response->headers->IsKeepAlive());
|
| + EXPECT_EQ(200, response->headers->response_code());
|
| + EXPECT_EQ(100, response->headers->GetContentLength());
|
| + EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
|
| + EXPECT_TRUE(response->was_fetched_via_proxy);
|
| +}
|
| +
|
| +// Test a basic HTTPS GET request through a proxy, but the server hangs up
|
| +// while establishing the tunnel.
|
| +TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) {
|
| + SessionDependencies session_deps(CreateFixedProxyService("myproxy:70"));
|
| + CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
|
| + session_deps.net_log = log.bound().net_log();
|
| + scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
|
| +
|
| + scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
|
| +
|
| + HttpRequestInfo request;
|
| + request.method = "GET";
|
| + request.url = GURL("https://www.google.com/");
|
| +
|
| + // Since we have proxy, should try to establish tunnel.
|
| + MockWrite data_writes1[] = {
|
| + MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
|
| + "Host: www.google.com\r\n"
|
| + "Proxy-Connection: keep-alive\r\n\r\n"),
|
| +
|
| + MockWrite("GET / HTTP/1.1\r\n"
|
| + "Host: www.google.com\r\n"
|
| + "Connection: keep-alive\r\n\r\n"),
|
| + };
|
| +
|
| + MockRead data_reads1[] = {
|
| + MockRead(false, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
|
| + MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
|
| + MockRead(true, 0, 0), // EOF
|
| + };
|
| +
|
| + StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
|
| + data_writes1, arraysize(data_writes1));
|
| + session_deps.socket_factory.AddSocketDataProvider(&data1);
|
| + SSLSocketDataProvider ssl(true, OK);
|
| + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
|
| +
|
| + TestCompletionCallback callback1;
|
| +
|
| + int rv = trans->Start(&request, &callback1, log.bound());
|
| + EXPECT_EQ(ERR_IO_PENDING, rv);
|
| +
|
| + rv = callback1.WaitForResult();
|
| + EXPECT_EQ(ERR_EMPTY_RESPONSE, rv);
|
| + size_t pos = ExpectLogContainsSomewhere(
|
| + log.entries(), 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
|
| + NetLog::PHASE_NONE);
|
| + ExpectLogContainsSomewhere(
|
| + log.entries(), pos,
|
| + NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
|
| + NetLog::PHASE_NONE);
|
| +}
|
| +
|
| } // namespace net
|
|
|