| 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 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 #include "net/http/http_network_session_peer.h" | 54 #include "net/http/http_network_session_peer.h" |
| 55 #include "net/http/http_request_headers.h" | 55 #include "net/http/http_request_headers.h" |
| 56 #include "net/http/http_response_info.h" | 56 #include "net/http/http_response_info.h" |
| 57 #include "net/http/http_server_properties_impl.h" | 57 #include "net/http/http_server_properties_impl.h" |
| 58 #include "net/http/http_stream.h" | 58 #include "net/http/http_stream.h" |
| 59 #include "net/http/http_stream_factory.h" | 59 #include "net/http/http_stream_factory.h" |
| 60 #include "net/http/http_stream_parser.h" | 60 #include "net/http/http_stream_parser.h" |
| 61 #include "net/http/http_transaction_test_util.h" | 61 #include "net/http/http_transaction_test_util.h" |
| 62 #include "net/log/net_log.h" | 62 #include "net/log/net_log.h" |
| 63 #include "net/log/net_log_event_type.h" | 63 #include "net/log/net_log_event_type.h" |
| 64 #include "net/log/net_log_source.h" |
| 64 #include "net/log/test_net_log.h" | 65 #include "net/log/test_net_log.h" |
| 65 #include "net/log/test_net_log_entry.h" | 66 #include "net/log/test_net_log_entry.h" |
| 66 #include "net/log/test_net_log_util.h" | 67 #include "net/log/test_net_log_util.h" |
| 67 #include "net/proxy/mock_proxy_resolver.h" | 68 #include "net/proxy/mock_proxy_resolver.h" |
| 68 #include "net/proxy/proxy_config_service_fixed.h" | 69 #include "net/proxy/proxy_config_service_fixed.h" |
| 69 #include "net/proxy/proxy_info.h" | 70 #include "net/proxy/proxy_info.h" |
| 70 #include "net/proxy/proxy_resolver.h" | 71 #include "net/proxy/proxy_resolver.h" |
| 71 #include "net/proxy/proxy_server.h" | 72 #include "net/proxy/proxy_server.h" |
| 72 #include "net/proxy/proxy_service.h" | 73 #include "net/proxy/proxy_service.h" |
| 73 #include "net/socket/client_socket_factory.h" | 74 #include "net/socket/client_socket_factory.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 std::string double_quote_headers; | 152 std::string double_quote_headers; |
| 152 base::JSONWriter::Write(*header_list, &double_quote_headers); | 153 base::JSONWriter::Write(*header_list, &double_quote_headers); |
| 153 base::ReplaceChars(double_quote_headers, "\"", "'", headers); | 154 base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
| 154 return true; | 155 return true; |
| 155 } | 156 } |
| 156 | 157 |
| 157 // Tests LoadTimingInfo in the case a socket is reused and no PAC script is | 158 // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 158 // used. | 159 // used. |
| 159 void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { | 160 void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
| 160 EXPECT_TRUE(load_timing_info.socket_reused); | 161 EXPECT_TRUE(load_timing_info.socket_reused); |
| 161 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 162 EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
| 162 | 163 |
| 163 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); | 164 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 164 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); | 165 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 165 | 166 |
| 166 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); | 167 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 167 EXPECT_FALSE(load_timing_info.send_start.is_null()); | 168 EXPECT_FALSE(load_timing_info.send_start.is_null()); |
| 168 | 169 |
| 169 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); | 170 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
| 170 | 171 |
| 171 // Set at a higher level. | 172 // Set at a higher level. |
| 172 EXPECT_TRUE(load_timing_info.request_start_time.is_null()); | 173 EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 173 EXPECT_TRUE(load_timing_info.request_start.is_null()); | 174 EXPECT_TRUE(load_timing_info.request_start.is_null()); |
| 174 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | 175 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
| 175 } | 176 } |
| 176 | 177 |
| 177 // Tests LoadTimingInfo in the case a new socket is used and no PAC script is | 178 // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 178 // used. | 179 // used. |
| 179 void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, | 180 void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
| 180 int connect_timing_flags) { | 181 int connect_timing_flags) { |
| 181 EXPECT_FALSE(load_timing_info.socket_reused); | 182 EXPECT_FALSE(load_timing_info.socket_reused); |
| 182 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 183 EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
| 183 | 184 |
| 184 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); | 185 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 185 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); | 186 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 186 | 187 |
| 187 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, | 188 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 188 connect_timing_flags); | 189 connect_timing_flags); |
| 189 EXPECT_LE(load_timing_info.connect_timing.connect_end, | 190 EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 190 load_timing_info.send_start); | 191 load_timing_info.send_start); |
| 191 | 192 |
| 192 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); | 193 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
| 193 | 194 |
| 194 // Set at a higher level. | 195 // Set at a higher level. |
| 195 EXPECT_TRUE(load_timing_info.request_start_time.is_null()); | 196 EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 196 EXPECT_TRUE(load_timing_info.request_start.is_null()); | 197 EXPECT_TRUE(load_timing_info.request_start.is_null()); |
| 197 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | 198 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
| 198 } | 199 } |
| 199 | 200 |
| 200 // Tests LoadTimingInfo in the case a socket is reused and a PAC script is | 201 // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 201 // used. | 202 // used. |
| 202 void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { | 203 void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
| 203 EXPECT_TRUE(load_timing_info.socket_reused); | 204 EXPECT_TRUE(load_timing_info.socket_reused); |
| 204 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 205 EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
| 205 | 206 |
| 206 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); | 207 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 207 | 208 |
| 208 EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); | 209 EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 209 EXPECT_LE(load_timing_info.proxy_resolve_start, | 210 EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 210 load_timing_info.proxy_resolve_end); | 211 load_timing_info.proxy_resolve_end); |
| 211 EXPECT_LE(load_timing_info.proxy_resolve_end, | 212 EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 212 load_timing_info.send_start); | 213 load_timing_info.send_start); |
| 213 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); | 214 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
| 214 | 215 |
| 215 // Set at a higher level. | 216 // Set at a higher level. |
| 216 EXPECT_TRUE(load_timing_info.request_start_time.is_null()); | 217 EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 217 EXPECT_TRUE(load_timing_info.request_start.is_null()); | 218 EXPECT_TRUE(load_timing_info.request_start.is_null()); |
| 218 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | 219 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
| 219 } | 220 } |
| 220 | 221 |
| 221 // Tests LoadTimingInfo in the case a new socket is used and a PAC script is | 222 // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 222 // used. | 223 // used. |
| 223 void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, | 224 void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
| 224 int connect_timing_flags) { | 225 int connect_timing_flags) { |
| 225 EXPECT_FALSE(load_timing_info.socket_reused); | 226 EXPECT_FALSE(load_timing_info.socket_reused); |
| 226 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 227 EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
| 227 | 228 |
| 228 EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); | 229 EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 229 EXPECT_LE(load_timing_info.proxy_resolve_start, | 230 EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 230 load_timing_info.proxy_resolve_end); | 231 load_timing_info.proxy_resolve_end); |
| 231 EXPECT_LE(load_timing_info.proxy_resolve_end, | 232 EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 232 load_timing_info.connect_timing.connect_start); | 233 load_timing_info.connect_timing.connect_start); |
| 233 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, | 234 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 234 connect_timing_flags); | 235 connect_timing_flags); |
| 235 EXPECT_LE(load_timing_info.connect_timing.connect_end, | 236 EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 236 load_timing_info.send_start); | 237 load_timing_info.send_start); |
| (...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1392 MockRead("world"), | 1393 MockRead("world"), |
| 1393 MockRead(ASYNC, OK), | 1394 MockRead(ASYNC, OK), |
| 1394 }; | 1395 }; |
| 1395 StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); | 1396 StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
| 1396 session_deps_.socket_factory->AddSocketDataProvider(&data2); | 1397 session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1397 | 1398 |
| 1398 const char* const kExpectedResponseData[] = { | 1399 const char* const kExpectedResponseData[] = { |
| 1399 "hello", "world" | 1400 "hello", "world" |
| 1400 }; | 1401 }; |
| 1401 | 1402 |
| 1402 uint32_t first_socket_log_id = NetLog::Source::kInvalidId; | 1403 uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
| 1403 for (int i = 0; i < 2; ++i) { | 1404 for (int i = 0; i < 2; ++i) { |
| 1404 TestCompletionCallback callback; | 1405 TestCompletionCallback callback; |
| 1405 | 1406 |
| 1406 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); | 1407 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1407 | 1408 |
| 1408 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); | 1409 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1409 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1410 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1410 | 1411 |
| 1411 rv = callback.WaitForResult(); | 1412 rv = callback.WaitForResult(); |
| 1412 EXPECT_THAT(rv, IsOk()); | 1413 EXPECT_THAT(rv, IsOk()); |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1832 MockRead(ASYNC, 22, "hello"), | 1833 MockRead(ASYNC, 22, "hello"), |
| 1833 }; | 1834 }; |
| 1834 SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, | 1835 SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 1835 arraysize(data_writes)); | 1836 arraysize(data_writes)); |
| 1836 data.set_busy_before_sync_reads(true); | 1837 data.set_busy_before_sync_reads(true); |
| 1837 session_deps_.socket_factory->AddSocketDataProvider(&data); | 1838 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1838 | 1839 |
| 1839 const int kNumUnreadBodies = arraysize(data_writes) - 1; | 1840 const int kNumUnreadBodies = arraysize(data_writes) - 1; |
| 1840 std::string response_lines[kNumUnreadBodies]; | 1841 std::string response_lines[kNumUnreadBodies]; |
| 1841 | 1842 |
| 1842 uint32_t first_socket_log_id = NetLog::Source::kInvalidId; | 1843 uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
| 1843 for (size_t i = 0; i < kNumUnreadBodies; ++i) { | 1844 for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
| 1844 TestCompletionCallback callback; | 1845 TestCompletionCallback callback; |
| 1845 | 1846 |
| 1846 std::unique_ptr<HttpNetworkTransaction> trans( | 1847 std::unique_ptr<HttpNetworkTransaction> trans( |
| 1847 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 1848 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1848 | 1849 |
| 1849 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); | 1850 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 1850 EXPECT_THAT(callback.GetResult(rv), IsOk()); | 1851 EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 1851 | 1852 |
| 1852 LoadTimingInfo load_timing_info; | 1853 LoadTimingInfo load_timing_info; |
| (...skipping 5766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7619 EXPECT_EQ("http://login.example.com/", url); | 7620 EXPECT_EQ("http://login.example.com/", url); |
| 7620 | 7621 |
| 7621 // In the case of redirects from proxies, HttpNetworkTransaction returns | 7622 // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7622 // timing for the proxy connection instead of the connection to the host, | 7623 // timing for the proxy connection instead of the connection to the host, |
| 7623 // and no send / receive times. | 7624 // and no send / receive times. |
| 7624 // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. | 7625 // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7625 LoadTimingInfo load_timing_info; | 7626 LoadTimingInfo load_timing_info; |
| 7626 EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); | 7627 EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 7627 | 7628 |
| 7628 EXPECT_FALSE(load_timing_info.socket_reused); | 7629 EXPECT_FALSE(load_timing_info.socket_reused); |
| 7629 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 7630 EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
| 7630 | 7631 |
| 7631 EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); | 7632 EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7632 EXPECT_LE(load_timing_info.proxy_resolve_start, | 7633 EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7633 load_timing_info.proxy_resolve_end); | 7634 load_timing_info.proxy_resolve_end); |
| 7634 EXPECT_LE(load_timing_info.proxy_resolve_end, | 7635 EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7635 load_timing_info.connect_timing.connect_start); | 7636 load_timing_info.connect_timing.connect_start); |
| 7636 ExpectConnectTimingHasTimes( | 7637 ExpectConnectTimingHasTimes( |
| 7637 load_timing_info.connect_timing, | 7638 load_timing_info.connect_timing, |
| 7638 CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); | 7639 CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7639 | 7640 |
| (...skipping 8228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15868 base::RunLoop().RunUntilIdle(); | 15869 base::RunLoop().RunUntilIdle(); |
| 15869 | 15870 |
| 15870 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); | 15871 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 15871 HttpRequestHeaders headers; | 15872 HttpRequestHeaders headers; |
| 15872 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); | 15873 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 15873 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); | 15874 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 15874 } | 15875 } |
| 15875 #endif // !defined(OS_IOS) | 15876 #endif // !defined(OS_IOS) |
| 15876 | 15877 |
| 15877 } // namespace net | 15878 } // namespace net |
| OLD | NEW |