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 <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 return observed_before_network_start_; | 426 return observed_before_network_start_; |
427 } | 427 } |
428 | 428 |
429 private: | 429 private: |
430 const bool defer_on_before_network_start_; | 430 const bool defer_on_before_network_start_; |
431 bool observed_before_network_start_; | 431 bool observed_before_network_start_; |
432 | 432 |
433 DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); | 433 DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
434 }; | 434 }; |
435 | 435 |
| 436 class BeforeProxyHeadersSentHandler { |
| 437 public: |
| 438 BeforeProxyHeadersSentHandler() |
| 439 : observed_before_proxy_headers_sent_(false) {} |
| 440 |
| 441 void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info) { |
| 442 observed_before_proxy_headers_sent_ = true; |
| 443 observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 444 } |
| 445 |
| 446 bool observed_before_proxy_headers_sent() const { |
| 447 return observed_before_proxy_headers_sent_; |
| 448 } |
| 449 |
| 450 std::string observed_proxy_server_uri() const { |
| 451 return observed_proxy_server_uri_; |
| 452 } |
| 453 |
| 454 private: |
| 455 bool observed_before_proxy_headers_sent_; |
| 456 std::string observed_proxy_server_uri_; |
| 457 |
| 458 DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 459 }; |
| 460 |
436 // Fill |str| with a long header list that consumes >= |size| bytes. | 461 // Fill |str| with a long header list that consumes >= |size| bytes. |
437 void FillLargeHeadersString(std::string* str, int size) { | 462 void FillLargeHeadersString(std::string* str, int size) { |
438 const char* row = | 463 const char* row = |
439 "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; | 464 "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
440 const int sizeof_row = strlen(row); | 465 const int sizeof_row = strlen(row); |
441 const int num_rows = static_cast<int>( | 466 const int num_rows = static_cast<int>( |
442 ceil(static_cast<float>(size) / sizeof_row)); | 467 ceil(static_cast<float>(size) / sizeof_row)); |
443 const int sizeof_data = num_rows * sizeof_row; | 468 const int sizeof_data = num_rows * sizeof_row; |
444 DCHECK(sizeof_data >= size); | 469 DCHECK(sizeof_data >= size); |
445 str->reserve(sizeof_data); | 470 str->reserve(sizeof_data); |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 // message body (since HEAD has none). | 992 // message body (since HEAD has none). |
968 TEST_P(HttpNetworkTransactionTest, Head) { | 993 TEST_P(HttpNetworkTransactionTest, Head) { |
969 HttpRequestInfo request; | 994 HttpRequestInfo request; |
970 request.method = "HEAD"; | 995 request.method = "HEAD"; |
971 request.url = GURL("http://www.google.com/"); | 996 request.url = GURL("http://www.google.com/"); |
972 request.load_flags = 0; | 997 request.load_flags = 0; |
973 | 998 |
974 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 999 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
975 scoped_ptr<HttpTransaction> trans( | 1000 scoped_ptr<HttpTransaction> trans( |
976 new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); | 1001 new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); |
| 1002 BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1003 trans->SetBeforeProxyHeadersSentCallback( |
| 1004 base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1005 base::Unretained(&proxy_headers_handler))); |
977 | 1006 |
978 MockWrite data_writes1[] = { | 1007 MockWrite data_writes1[] = { |
979 MockWrite("HEAD / HTTP/1.1\r\n" | 1008 MockWrite("HEAD / HTTP/1.1\r\n" |
980 "Host: www.google.com\r\n" | 1009 "Host: www.google.com\r\n" |
981 "Connection: keep-alive\r\n" | 1010 "Connection: keep-alive\r\n" |
982 "Content-Length: 0\r\n\r\n"), | 1011 "Content-Length: 0\r\n\r\n"), |
983 }; | 1012 }; |
984 MockRead data_reads1[] = { | 1013 MockRead data_reads1[] = { |
985 MockRead("HTTP/1.1 404 Not Found\r\n"), | 1014 MockRead("HTTP/1.1 404 Not Found\r\n"), |
986 MockRead("Server: Blah\r\n"), | 1015 MockRead("Server: Blah\r\n"), |
(...skipping 16 matching lines...) Expand all Loading... |
1003 EXPECT_EQ(OK, rv); | 1032 EXPECT_EQ(OK, rv); |
1004 | 1033 |
1005 const HttpResponseInfo* response = trans->GetResponseInfo(); | 1034 const HttpResponseInfo* response = trans->GetResponseInfo(); |
1006 ASSERT_TRUE(response != NULL); | 1035 ASSERT_TRUE(response != NULL); |
1007 | 1036 |
1008 // Check that the headers got parsed. | 1037 // Check that the headers got parsed. |
1009 EXPECT_TRUE(response->headers.get() != NULL); | 1038 EXPECT_TRUE(response->headers.get() != NULL); |
1010 EXPECT_EQ(1234, response->headers->GetContentLength()); | 1039 EXPECT_EQ(1234, response->headers->GetContentLength()); |
1011 EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); | 1040 EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
1012 EXPECT_TRUE(response->proxy_server.IsEmpty()); | 1041 EXPECT_TRUE(response->proxy_server.IsEmpty()); |
| 1042 EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
1013 | 1043 |
1014 std::string server_header; | 1044 std::string server_header; |
1015 void* iter = NULL; | 1045 void* iter = NULL; |
1016 bool has_server_header = response->headers->EnumerateHeader( | 1046 bool has_server_header = response->headers->EnumerateHeader( |
1017 &iter, "Server", &server_header); | 1047 &iter, "Server", &server_header); |
1018 EXPECT_TRUE(has_server_header); | 1048 EXPECT_TRUE(has_server_header); |
1019 EXPECT_EQ("Blah", server_header); | 1049 EXPECT_EQ("Blah", server_header); |
1020 | 1050 |
1021 // Reading should give EOF right away, since there is no message body | 1051 // Reading should give EOF right away, since there is no message body |
1022 // (despite non-zero content-length). | 1052 // (despite non-zero content-length). |
(...skipping 9310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10333 }; | 10363 }; |
10334 | 10364 |
10335 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | 10365 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
10336 data_writes1, arraysize(data_writes1)); | 10366 data_writes1, arraysize(data_writes1)); |
10337 session_deps_.socket_factory->AddSocketDataProvider(&data1); | 10367 session_deps_.socket_factory->AddSocketDataProvider(&data1); |
10338 | 10368 |
10339 TestCompletionCallback callback1; | 10369 TestCompletionCallback callback1; |
10340 | 10370 |
10341 scoped_ptr<HttpTransaction> trans( | 10371 scoped_ptr<HttpTransaction> trans( |
10342 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 10372 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10373 BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 10374 trans->SetBeforeProxyHeadersSentCallback( |
| 10375 base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 10376 base::Unretained(&proxy_headers_handler))); |
10343 | 10377 |
10344 int rv = trans->Start(&request, callback1.callback(), log.bound()); | 10378 int rv = trans->Start(&request, callback1.callback(), log.bound()); |
10345 EXPECT_EQ(ERR_IO_PENDING, rv); | 10379 EXPECT_EQ(ERR_IO_PENDING, rv); |
10346 | 10380 |
10347 rv = callback1.WaitForResult(); | 10381 rv = callback1.WaitForResult(); |
10348 EXPECT_EQ(OK, rv); | 10382 EXPECT_EQ(OK, rv); |
10349 | 10383 |
10350 const HttpResponseInfo* response = trans->GetResponseInfo(); | 10384 const HttpResponseInfo* response = trans->GetResponseInfo(); |
10351 ASSERT_TRUE(response != NULL); | 10385 ASSERT_TRUE(response != NULL); |
10352 | 10386 |
10353 EXPECT_TRUE(response->headers->IsKeepAlive()); | 10387 EXPECT_TRUE(response->headers->IsKeepAlive()); |
10354 EXPECT_EQ(200, response->headers->response_code()); | 10388 EXPECT_EQ(200, response->headers->response_code()); |
10355 EXPECT_EQ(100, response->headers->GetContentLength()); | 10389 EXPECT_EQ(100, response->headers->GetContentLength()); |
10356 EXPECT_TRUE(response->was_fetched_via_proxy); | 10390 EXPECT_TRUE(response->was_fetched_via_proxy); |
10357 EXPECT_TRUE( | 10391 EXPECT_TRUE( |
10358 response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); | 10392 response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
| 10393 EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 10394 EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
10359 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | 10395 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
10360 | 10396 |
10361 LoadTimingInfo load_timing_info; | 10397 LoadTimingInfo load_timing_info; |
10362 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | 10398 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
10363 TestLoadTimingNotReusedWithPac(load_timing_info, | 10399 TestLoadTimingNotReusedWithPac(load_timing_info, |
10364 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); | 10400 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
10365 } | 10401 } |
10366 | 10402 |
10367 // Test a basic HTTPS GET request through a proxy. | 10403 // Test a basic HTTPS GET request through a proxy. |
10368 TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { | 10404 TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
(...skipping 2812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13181 EXPECT_EQ(ERR_IO_PENDING, rv); | 13217 EXPECT_EQ(ERR_IO_PENDING, rv); |
13182 | 13218 |
13183 rv = callback.WaitForResult(); | 13219 rv = callback.WaitForResult(); |
13184 EXPECT_EQ(ERR_CONNECTION_RESET, rv); | 13220 EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
13185 | 13221 |
13186 const HttpResponseInfo* response = trans->GetResponseInfo(); | 13222 const HttpResponseInfo* response = trans->GetResponseInfo(); |
13187 EXPECT_TRUE(response == NULL); | 13223 EXPECT_TRUE(response == NULL); |
13188 } | 13224 } |
13189 | 13225 |
13190 } // namespace net | 13226 } // namespace net |
OLD | NEW |