| 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 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 | 1056 |
| 1057 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 1057 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 1058 | 1058 |
| 1059 const HttpResponseInfo* response = trans.GetResponseInfo(); | 1059 const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1060 ASSERT_TRUE(response); | 1060 ASSERT_TRUE(response); |
| 1061 ASSERT_TRUE(response->headers); | 1061 ASSERT_TRUE(response->headers); |
| 1062 EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); | 1062 EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1063 std::string url; | 1063 std::string url; |
| 1064 EXPECT_TRUE(response->headers->IsRedirect(&url)); | 1064 EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1065 EXPECT_EQ("http://good.com/", url); | 1065 EXPECT_EQ("http://good.com/", url); |
| 1066 EXPECT_TRUE(response->proxy_server.IsEmpty()); | 1066 EXPECT_FALSE(response->proxy_server.is_valid()); |
| 1067 } | 1067 } |
| 1068 | 1068 |
| 1069 // Checks that two distinct Location headers result in an error. | 1069 // Checks that two distinct Location headers result in an error. |
| 1070 TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { | 1070 TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
| 1071 MockRead data_reads[] = { | 1071 MockRead data_reads[] = { |
| 1072 MockRead("HTTP/1.1 302 Redirect\r\n"), | 1072 MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1073 MockRead("Location: http://good.com/\r\n"), | 1073 MockRead("Location: http://good.com/\r\n"), |
| 1074 MockRead("Location: http://evil.com/\r\n"), | 1074 MockRead("Location: http://evil.com/\r\n"), |
| 1075 MockRead("Content-Length: 0\r\n\r\n"), | 1075 MockRead("Content-Length: 0\r\n\r\n"), |
| 1076 MockRead(SYNCHRONOUS, OK), | 1076 MockRead(SYNCHRONOUS, OK), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 rv = callback1.WaitForResult(); | 1120 rv = callback1.WaitForResult(); |
| 1121 EXPECT_THAT(rv, IsOk()); | 1121 EXPECT_THAT(rv, IsOk()); |
| 1122 | 1122 |
| 1123 const HttpResponseInfo* response = trans.GetResponseInfo(); | 1123 const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1124 ASSERT_TRUE(response); | 1124 ASSERT_TRUE(response); |
| 1125 | 1125 |
| 1126 // Check that the headers got parsed. | 1126 // Check that the headers got parsed. |
| 1127 EXPECT_TRUE(response->headers); | 1127 EXPECT_TRUE(response->headers); |
| 1128 EXPECT_EQ(1234, response->headers->GetContentLength()); | 1128 EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1129 EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); | 1129 EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
| 1130 EXPECT_TRUE(response->proxy_server.IsEmpty()); | 1130 EXPECT_FALSE(response->proxy_server.is_valid()); |
| 1131 EXPECT_TRUE(headers_handler.observed_before_headers_sent()); | 1131 EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1132 EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); | 1132 EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 1133 | 1133 |
| 1134 std::string server_header; | 1134 std::string server_header; |
| 1135 size_t iter = 0; | 1135 size_t iter = 0; |
| 1136 bool has_server_header = response->headers->EnumerateHeader( | 1136 bool has_server_header = response->headers->EnumerateHeader( |
| 1137 &iter, "Server", &server_header); | 1137 &iter, "Server", &server_header); |
| 1138 EXPECT_TRUE(has_server_header); | 1138 EXPECT_TRUE(has_server_header); |
| 1139 EXPECT_EQ("Blah", server_header); | 1139 EXPECT_EQ("Blah", server_header); |
| 1140 | 1140 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1177 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1178 | 1178 |
| 1179 rv = callback.WaitForResult(); | 1179 rv = callback.WaitForResult(); |
| 1180 EXPECT_THAT(rv, IsOk()); | 1180 EXPECT_THAT(rv, IsOk()); |
| 1181 | 1181 |
| 1182 const HttpResponseInfo* response = trans.GetResponseInfo(); | 1182 const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1183 ASSERT_TRUE(response); | 1183 ASSERT_TRUE(response); |
| 1184 | 1184 |
| 1185 EXPECT_TRUE(response->headers); | 1185 EXPECT_TRUE(response->headers); |
| 1186 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 1186 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1187 EXPECT_TRUE(response->proxy_server.IsEmpty()); | 1187 EXPECT_FALSE(response->proxy_server.is_valid()); |
| 1188 | 1188 |
| 1189 std::string response_data; | 1189 std::string response_data; |
| 1190 rv = ReadTransaction(&trans, &response_data); | 1190 rv = ReadTransaction(&trans, &response_data); |
| 1191 EXPECT_THAT(rv, IsOk()); | 1191 EXPECT_THAT(rv, IsOk()); |
| 1192 EXPECT_EQ(kExpectedResponseData[i], response_data); | 1192 EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 1193 } | 1193 } |
| 1194 } | 1194 } |
| 1195 | 1195 |
| 1196 TEST_F(HttpNetworkTransactionTest, Ignores100) { | 1196 TEST_F(HttpNetworkTransactionTest, Ignores100) { |
| 1197 std::vector<std::unique_ptr<UploadElementReader>> element_readers; | 1197 std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| (...skipping 10923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12121 rv = callback1.WaitForResult(); | 12121 rv = callback1.WaitForResult(); |
| 12122 EXPECT_THAT(rv, IsOk()); | 12122 EXPECT_THAT(rv, IsOk()); |
| 12123 | 12123 |
| 12124 const HttpResponseInfo* response = trans.GetResponseInfo(); | 12124 const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12125 ASSERT_TRUE(response); | 12125 ASSERT_TRUE(response); |
| 12126 | 12126 |
| 12127 EXPECT_TRUE(response->headers->IsKeepAlive()); | 12127 EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12128 EXPECT_EQ(200, response->headers->response_code()); | 12128 EXPECT_EQ(200, response->headers->response_code()); |
| 12129 EXPECT_EQ(100, response->headers->GetContentLength()); | 12129 EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12130 EXPECT_TRUE(response->was_fetched_via_proxy); | 12130 EXPECT_TRUE(response->was_fetched_via_proxy); |
| 12131 EXPECT_TRUE( | 12131 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12132 response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); | 12132 HostPortPair::FromString("myproxy:70")), |
| 12133 response->proxy_server); |
| 12133 EXPECT_TRUE(headers_handler.observed_before_headers_sent()); | 12134 EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12134 EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); | 12135 EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12135 EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); | 12136 EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
| 12136 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | 12137 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12137 | 12138 |
| 12138 LoadTimingInfo load_timing_info; | 12139 LoadTimingInfo load_timing_info; |
| 12139 EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); | 12140 EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 12140 TestLoadTimingNotReusedWithPac(load_timing_info, | 12141 TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12141 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); | 12142 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 12142 } | 12143 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12203 NetLogEventPhase::NONE); | 12204 NetLogEventPhase::NONE); |
| 12204 | 12205 |
| 12205 const HttpResponseInfo* response = trans.GetResponseInfo(); | 12206 const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12206 ASSERT_TRUE(response); | 12207 ASSERT_TRUE(response); |
| 12207 | 12208 |
| 12208 EXPECT_TRUE(response->headers->IsKeepAlive()); | 12209 EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12209 EXPECT_EQ(200, response->headers->response_code()); | 12210 EXPECT_EQ(200, response->headers->response_code()); |
| 12210 EXPECT_EQ(100, response->headers->GetContentLength()); | 12211 EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12211 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | 12212 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12212 EXPECT_TRUE(response->was_fetched_via_proxy); | 12213 EXPECT_TRUE(response->was_fetched_via_proxy); |
| 12213 EXPECT_TRUE( | 12214 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12214 response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); | 12215 HostPortPair::FromString("myproxy:70")), |
| 12216 response->proxy_server); |
| 12215 EXPECT_TRUE(headers_handler.observed_before_headers_sent()); | 12217 EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12216 EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); | 12218 EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12217 EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); | 12219 EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
| 12218 | 12220 |
| 12219 LoadTimingInfo load_timing_info; | 12221 LoadTimingInfo load_timing_info; |
| 12220 EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); | 12222 EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 12221 TestLoadTimingNotReusedWithPac(load_timing_info, | 12223 TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12222 CONNECT_TIMING_HAS_SSL_TIMES); | 12224 CONNECT_TIMING_HAS_SSL_TIMES); |
| 12223 } | 12225 } |
| 12224 | 12226 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12281 NetLogEventPhase::NONE); | 12283 NetLogEventPhase::NONE); |
| 12282 | 12284 |
| 12283 const HttpResponseInfo* response = trans.GetResponseInfo(); | 12285 const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12284 ASSERT_TRUE(response); | 12286 ASSERT_TRUE(response); |
| 12285 | 12287 |
| 12286 EXPECT_TRUE(response->headers->IsKeepAlive()); | 12288 EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12287 EXPECT_EQ(200, response->headers->response_code()); | 12289 EXPECT_EQ(200, response->headers->response_code()); |
| 12288 EXPECT_EQ(100, response->headers->GetContentLength()); | 12290 EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12289 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | 12291 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12290 EXPECT_TRUE(response->was_fetched_via_proxy); | 12292 EXPECT_TRUE(response->was_fetched_via_proxy); |
| 12291 EXPECT_TRUE( | 12293 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12292 response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); | 12294 HostPortPair::FromString("myproxy:70")), |
| 12295 response->proxy_server); |
| 12293 | 12296 |
| 12294 LoadTimingInfo load_timing_info; | 12297 LoadTimingInfo load_timing_info; |
| 12295 EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); | 12298 EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 12296 TestLoadTimingNotReusedWithPac(load_timing_info, | 12299 TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12297 CONNECT_TIMING_HAS_SSL_TIMES); | 12300 CONNECT_TIMING_HAS_SSL_TIMES); |
| 12298 } | 12301 } |
| 12299 | 12302 |
| 12300 // Test a basic HTTPS GET request through a proxy, but the server hangs up | 12303 // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12301 // while establishing the tunnel. | 12304 // while establishing the tunnel. |
| 12302 TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { | 12305 TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
| (...skipping 3272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15575 base::RunLoop().RunUntilIdle(); | 15578 base::RunLoop().RunUntilIdle(); |
| 15576 | 15579 |
| 15577 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); | 15580 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 15578 HttpRequestHeaders headers; | 15581 HttpRequestHeaders headers; |
| 15579 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); | 15582 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 15580 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); | 15583 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 15581 } | 15584 } |
| 15582 #endif // !defined(OS_IOS) | 15585 #endif // !defined(OS_IOS) |
| 15583 | 15586 |
| 15584 } // namespace net | 15587 } // namespace net |
| OLD | NEW |