| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
| 6 | 6 |
| 7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
| 8 #include <stdarg.h> | 8 #include <stdarg.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 return out; | 390 return out; |
| 391 } | 391 } |
| 392 out.status_line = response->headers->GetStatusLine(); | 392 out.status_line = response->headers->GetStatusLine(); |
| 393 | 393 |
| 394 EXPECT_EQ("127.0.0.1", response->socket_address.host()); | 394 EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 395 EXPECT_EQ(80, response->socket_address.port()); | 395 EXPECT_EQ(80, response->socket_address.port()); |
| 396 | 396 |
| 397 bool got_endpoint = | 397 bool got_endpoint = |
| 398 trans->GetRemoteEndpoint(&out.remote_endpoint_after_start); | 398 trans->GetRemoteEndpoint(&out.remote_endpoint_after_start); |
| 399 EXPECT_EQ(got_endpoint, | 399 EXPECT_EQ(got_endpoint, |
| 400 out.remote_endpoint_after_start.address().size() > 0); | 400 out.remote_endpoint_after_start.address_number().size() > 0); |
| 401 | 401 |
| 402 rv = ReadTransaction(trans.get(), &out.response_data); | 402 rv = ReadTransaction(trans.get(), &out.response_data); |
| 403 EXPECT_EQ(OK, rv); | 403 EXPECT_EQ(OK, rv); |
| 404 | 404 |
| 405 TestNetLogEntry::List entries; | 405 TestNetLogEntry::List entries; |
| 406 log.GetEntries(&entries); | 406 log.GetEntries(&entries); |
| 407 size_t pos = ExpectLogContainsSomewhere( | 407 size_t pos = ExpectLogContainsSomewhere( |
| 408 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, | 408 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 409 NetLog::PHASE_NONE); | 409 NetLog::PHASE_NONE); |
| 410 ExpectLogContainsSomewhere( | 410 ExpectLogContainsSomewhere( |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 }; | 719 }; |
| 720 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 720 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 721 arraysize(data_reads)); | 721 arraysize(data_reads)); |
| 722 EXPECT_EQ(OK, out.rv); | 722 EXPECT_EQ(OK, out.rv); |
| 723 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); | 723 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 724 EXPECT_EQ("hello world", out.response_data); | 724 EXPECT_EQ("hello world", out.response_data); |
| 725 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); | 725 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 726 EXPECT_EQ(reads_size, out.total_received_bytes); | 726 EXPECT_EQ(reads_size, out.total_received_bytes); |
| 727 EXPECT_EQ(0u, out.connection_attempts.size()); | 727 EXPECT_EQ(0u, out.connection_attempts.size()); |
| 728 | 728 |
| 729 EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); | 729 EXPECT_FALSE(out.remote_endpoint_after_start.address_number().empty()); |
| 730 } | 730 } |
| 731 | 731 |
| 732 // Response with no status line. | 732 // Response with no status line. |
| 733 TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { | 733 TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
| 734 MockRead data_reads[] = { | 734 MockRead data_reads[] = { |
| 735 MockRead("hello world"), | 735 MockRead("hello world"), |
| 736 MockRead(SYNCHRONOUS, OK), | 736 MockRead(SYNCHRONOUS, OK), |
| 737 }; | 737 }; |
| 738 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 738 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 739 arraysize(data_reads)); | 739 arraysize(data_reads)); |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1638 TestCompletionCallback callback; | 1638 TestCompletionCallback callback; |
| 1639 | 1639 |
| 1640 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 1640 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1641 EXPECT_EQ(ERR_IO_PENDING, rv); | 1641 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1642 | 1642 |
| 1643 rv = callback.WaitForResult(); | 1643 rv = callback.WaitForResult(); |
| 1644 EXPECT_EQ(ERR_CONNECTION_RESET, rv); | 1644 EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 1645 | 1645 |
| 1646 IPEndPoint endpoint; | 1646 IPEndPoint endpoint; |
| 1647 EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); | 1647 EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 1648 EXPECT_LT(0u, endpoint.address().size()); | 1648 EXPECT_LT(0u, endpoint.address_number().size()); |
| 1649 } | 1649 } |
| 1650 | 1650 |
| 1651 // What do various browsers do when the server closes a non-keepalive | 1651 // What do various browsers do when the server closes a non-keepalive |
| 1652 // connection without sending any response header or body? | 1652 // connection without sending any response header or body? |
| 1653 // | 1653 // |
| 1654 // IE7: error page | 1654 // IE7: error page |
| 1655 // Safari 3.1.2 (Windows): error page | 1655 // Safari 3.1.2 (Windows): error page |
| 1656 // Firefox 3.0.1: blank page | 1656 // Firefox 3.0.1: blank page |
| 1657 // Opera 9.52: after five attempts, blank page | 1657 // Opera 9.52: after five attempts, blank page |
| 1658 // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) | 1658 // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2150 EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); | 2150 EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2151 int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); | 2151 int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
| 2152 EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); | 2152 EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2153 | 2153 |
| 2154 const HttpResponseInfo* response = trans->GetResponseInfo(); | 2154 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2155 ASSERT_TRUE(response); | 2155 ASSERT_TRUE(response); |
| 2156 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); | 2156 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2157 | 2157 |
| 2158 IPEndPoint endpoint; | 2158 IPEndPoint endpoint; |
| 2159 EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); | 2159 EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2160 ASSERT_FALSE(endpoint.address().empty()); | 2160 ASSERT_FALSE(endpoint.address_number().empty()); |
| 2161 EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); | 2161 EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2162 | 2162 |
| 2163 resolver->rules()->ClearRules(); | 2163 resolver->rules()->ClearRules(); |
| 2164 resolver->rules()->AddRule("www.example.org", "127.0.0.2"); | 2164 resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2165 | 2165 |
| 2166 TestCompletionCallback callback2; | 2166 TestCompletionCallback callback2; |
| 2167 | 2167 |
| 2168 EXPECT_EQ(OK, callback2.GetResult(trans->RestartWithAuth( | 2168 EXPECT_EQ(OK, callback2.GetResult(trans->RestartWithAuth( |
| 2169 AuthCredentials(kFoo, kBar), callback2.callback()))); | 2169 AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2170 | 2170 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2181 EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); | 2181 EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2182 int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); | 2182 int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
| 2183 EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); | 2183 EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2184 | 2184 |
| 2185 response = trans->GetResponseInfo(); | 2185 response = trans->GetResponseInfo(); |
| 2186 ASSERT_TRUE(response); | 2186 ASSERT_TRUE(response); |
| 2187 EXPECT_FALSE(response->auth_challenge.get()); | 2187 EXPECT_FALSE(response->auth_challenge.get()); |
| 2188 EXPECT_EQ(100, response->headers->GetContentLength()); | 2188 EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2189 | 2189 |
| 2190 EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); | 2190 EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2191 ASSERT_FALSE(endpoint.address().empty()); | 2191 ASSERT_FALSE(endpoint.address_number().empty()); |
| 2192 EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); | 2192 EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2193 } | 2193 } |
| 2194 | 2194 |
| 2195 TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { | 2195 TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
| 2196 HttpRequestInfo request; | 2196 HttpRequestInfo request; |
| 2197 request.method = "GET"; | 2197 request.method = "GET"; |
| 2198 request.url = GURL("http://www.example.org/"); | 2198 request.url = GURL("http://www.example.org/"); |
| 2199 request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; | 2199 request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2200 | 2200 |
| 2201 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 2201 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| (...skipping 6852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9054 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 9054 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9055 | 9055 |
| 9056 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 9056 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9057 EXPECT_EQ(ERR_IO_PENDING, rv); | 9057 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9058 | 9058 |
| 9059 rv = callback.WaitForResult(); | 9059 rv = callback.WaitForResult(); |
| 9060 EXPECT_EQ(ERR_CONNECTION_RESET, rv); | 9060 EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 9061 | 9061 |
| 9062 IPEndPoint endpoint; | 9062 IPEndPoint endpoint; |
| 9063 EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); | 9063 EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 9064 EXPECT_LT(0u, endpoint.address().size()); | 9064 EXPECT_LT(0u, endpoint.address_number().size()); |
| 9065 } | 9065 } |
| 9066 | 9066 |
| 9067 // Check that a connection closed after the start of the headers finishes ok. | 9067 // Check that a connection closed after the start of the headers finishes ok. |
| 9068 TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { | 9068 TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
| 9069 HttpRequestInfo request; | 9069 HttpRequestInfo request; |
| 9070 request.method = "GET"; | 9070 request.method = "GET"; |
| 9071 request.url = GURL("http://www.foo.com/"); | 9071 request.url = GURL("http://www.foo.com/"); |
| 9072 request.load_flags = 0; | 9072 request.load_flags = 0; |
| 9073 | 9073 |
| 9074 MockRead data_reads[] = { | 9074 MockRead data_reads[] = { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 9097 EXPECT_TRUE(response->headers.get() != NULL); | 9097 EXPECT_TRUE(response->headers.get() != NULL); |
| 9098 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); | 9098 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9099 | 9099 |
| 9100 std::string response_data; | 9100 std::string response_data; |
| 9101 rv = ReadTransaction(trans.get(), &response_data); | 9101 rv = ReadTransaction(trans.get(), &response_data); |
| 9102 EXPECT_EQ(OK, rv); | 9102 EXPECT_EQ(OK, rv); |
| 9103 EXPECT_EQ("", response_data); | 9103 EXPECT_EQ("", response_data); |
| 9104 | 9104 |
| 9105 IPEndPoint endpoint; | 9105 IPEndPoint endpoint; |
| 9106 EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); | 9106 EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 9107 EXPECT_LT(0u, endpoint.address().size()); | 9107 EXPECT_LT(0u, endpoint.address_number().size()); |
| 9108 } | 9108 } |
| 9109 | 9109 |
| 9110 // Make sure that a dropped connection while draining the body for auth | 9110 // Make sure that a dropped connection while draining the body for auth |
| 9111 // restart does the right thing. | 9111 // restart does the right thing. |
| 9112 TEST_P(HttpNetworkTransactionTest, DrainResetOK) { | 9112 TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
| 9113 HttpRequestInfo request; | 9113 HttpRequestInfo request; |
| 9114 request.method = "GET"; | 9114 request.method = "GET"; |
| 9115 request.url = GURL("http://www.example.org/"); | 9115 request.url = GURL("http://www.example.org/"); |
| 9116 request.load_flags = 0; | 9116 request.load_flags = 0; |
| 9117 | 9117 |
| (...skipping 4986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14104 HttpRequestHeaders request_headers; | 14104 HttpRequestHeaders request_headers; |
| 14105 trans->GetFullRequestHeaders(&request_headers); | 14105 trans->GetFullRequestHeaders(&request_headers); |
| 14106 | 14106 |
| 14107 ConnectionAttempts attempts; | 14107 ConnectionAttempts attempts; |
| 14108 trans->GetConnectionAttempts(&attempts); | 14108 trans->GetConnectionAttempts(&attempts); |
| 14109 ASSERT_EQ(1u, attempts.size()); | 14109 ASSERT_EQ(1u, attempts.size()); |
| 14110 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); | 14110 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 14111 | 14111 |
| 14112 IPEndPoint endpoint; | 14112 IPEndPoint endpoint; |
| 14113 EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); | 14113 EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 14114 EXPECT_TRUE(endpoint.address().empty()); | 14114 EXPECT_TRUE(endpoint.address_number().empty()); |
| 14115 } | 14115 } |
| 14116 | 14116 |
| 14117 TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { | 14117 TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 14118 HttpRequestInfo request; | 14118 HttpRequestInfo request; |
| 14119 request.method = "GET"; | 14119 request.method = "GET"; |
| 14120 request.url = GURL("http://www.example.org/"); | 14120 request.url = GURL("http://www.example.org/"); |
| 14121 request.load_flags = 0; | 14121 request.load_flags = 0; |
| 14122 | 14122 |
| 14123 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 14123 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14124 scoped_ptr<HttpTransaction> trans( | 14124 scoped_ptr<HttpTransaction> trans( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 14141 HttpRequestHeaders request_headers; | 14141 HttpRequestHeaders request_headers; |
| 14142 trans->GetFullRequestHeaders(&request_headers); | 14142 trans->GetFullRequestHeaders(&request_headers); |
| 14143 | 14143 |
| 14144 ConnectionAttempts attempts; | 14144 ConnectionAttempts attempts; |
| 14145 trans->GetConnectionAttempts(&attempts); | 14145 trans->GetConnectionAttempts(&attempts); |
| 14146 ASSERT_EQ(1u, attempts.size()); | 14146 ASSERT_EQ(1u, attempts.size()); |
| 14147 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); | 14147 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 14148 | 14148 |
| 14149 IPEndPoint endpoint; | 14149 IPEndPoint endpoint; |
| 14150 EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); | 14150 EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 14151 EXPECT_TRUE(endpoint.address().empty()); | 14151 EXPECT_TRUE(endpoint.address_number().empty()); |
| 14152 } | 14152 } |
| 14153 | 14153 |
| 14154 TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { | 14154 TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 14155 HttpRequestInfo request; | 14155 HttpRequestInfo request; |
| 14156 request.method = "GET"; | 14156 request.method = "GET"; |
| 14157 request.url = GURL("http://www.example.org/"); | 14157 request.url = GURL("http://www.example.org/"); |
| 14158 request.load_flags = 0; | 14158 request.load_flags = 0; |
| 14159 | 14159 |
| 14160 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 14160 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14161 scoped_ptr<HttpTransaction> trans( | 14161 scoped_ptr<HttpTransaction> trans( |
| (...skipping 1634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15796 | 15796 |
| 15797 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 15797 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15798 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); | 15798 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15799 | 15799 |
| 15800 EXPECT_THAT(trans.server_ssl_config_.alpn_protos, | 15800 EXPECT_THAT(trans.server_ssl_config_.alpn_protos, |
| 15801 testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); | 15801 testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15802 EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty()); | 15802 EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty()); |
| 15803 } | 15803 } |
| 15804 | 15804 |
| 15805 } // namespace net | 15805 } // namespace net |
| OLD | NEW |