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 7519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7530 bool ssl; | 7530 bool ssl; |
7531 }; | 7531 }; |
7532 | 7532 |
7533 scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( | 7533 scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
7534 NextProto next_proto, | 7534 NextProto next_proto, |
7535 SpdySessionDependencies* session_deps_) { | 7535 SpdySessionDependencies* session_deps_) { |
7536 scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); | 7536 scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
7537 | 7537 |
7538 base::WeakPtr<HttpServerProperties> http_server_properties = | 7538 base::WeakPtr<HttpServerProperties> http_server_properties = |
7539 session->http_server_properties(); | 7539 session->http_server_properties(); |
7540 http_server_properties->SetAlternateProtocol( | 7540 http_server_properties->AddAlternateProtocol( |
7541 HostPortPair("host.with.alternate", 80), 443, | 7541 HostPortPair("host.with.alternate", 80), 443, |
7542 AlternateProtocolFromNextProto(next_proto), 1); | 7542 AlternateProtocolFromNextProto(next_proto), 1); |
7543 | 7543 |
7544 return session; | 7544 return session; |
7545 } | 7545 } |
7546 | 7546 |
7547 int GroupNameTransactionHelper( | 7547 int GroupNameTransactionHelper( |
7548 const std::string& url, | 7548 const std::string& url, |
7549 const scoped_refptr<HttpNetworkSession>& session) { | 7549 const scoped_refptr<HttpNetworkSession>& session) { |
7550 HttpRequestInfo request; | 7550 HttpRequestInfo request; |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8441 ASSERT_TRUE(response->headers.get() != NULL); | 8441 ASSERT_TRUE(response->headers.get() != NULL); |
8442 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 8442 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
8443 EXPECT_FALSE(response->was_fetched_via_spdy); | 8443 EXPECT_FALSE(response->was_fetched_via_spdy); |
8444 EXPECT_FALSE(response->was_npn_negotiated); | 8444 EXPECT_FALSE(response->was_npn_negotiated); |
8445 | 8445 |
8446 std::string response_data; | 8446 std::string response_data; |
8447 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 8447 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
8448 EXPECT_EQ("hello world", response_data); | 8448 EXPECT_EQ("hello world", response_data); |
8449 | 8449 |
8450 ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair)); | 8450 ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair)); |
8451 const AlternateProtocolInfo alternate = | 8451 const AlternateProtocols alternate_protocols = |
8452 http_server_properties.GetAlternateProtocol(http_host_port_pair); | 8452 http_server_properties.GetAlternateProtocols(http_host_port_pair); |
| 8453 ASSERT_EQ(1u, alternate_protocols.size()); |
8453 AlternateProtocolInfo expected_alternate( | 8454 AlternateProtocolInfo expected_alternate( |
8454 443, AlternateProtocolFromNextProto(GetParam()), 1); | 8455 443, AlternateProtocolFromNextProto(GetParam()), 1); |
8455 EXPECT_TRUE(expected_alternate.Equals(alternate)); | 8456 EXPECT_TRUE(expected_alternate.Equals(alternate_protocols[0])); |
8456 } | 8457 } |
8457 | 8458 |
8458 TEST_P(HttpNetworkTransactionTest, | 8459 TEST_P(HttpNetworkTransactionTest, |
8459 MarkBrokenAlternateProtocolAndFallback) { | 8460 MarkBrokenAlternateProtocolAndFallback) { |
8460 session_deps_.use_alternate_protocols = true; | 8461 session_deps_.use_alternate_protocols = true; |
8461 | 8462 |
8462 HttpRequestInfo request; | 8463 HttpRequestInfo request; |
8463 request.method = "GET"; | 8464 request.method = "GET"; |
8464 request.url = GURL("http://www.google.com/"); | 8465 request.url = GURL("http://www.google.com/"); |
8465 request.load_flags = 0; | 8466 request.load_flags = 0; |
(...skipping 11 matching lines...) Expand all Loading... |
8477 StaticSocketDataProvider second_data( | 8478 StaticSocketDataProvider second_data( |
8478 data_reads, arraysize(data_reads), NULL, 0); | 8479 data_reads, arraysize(data_reads), NULL, 0); |
8479 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | 8480 session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
8480 | 8481 |
8481 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 8482 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
8482 | 8483 |
8483 base::WeakPtr<HttpServerProperties> http_server_properties = | 8484 base::WeakPtr<HttpServerProperties> http_server_properties = |
8484 session->http_server_properties(); | 8485 session->http_server_properties(); |
8485 // Port must be < 1024, or the header will be ignored (since initial port was | 8486 // Port must be < 1024, or the header will be ignored (since initial port was |
8486 // port 80 (another restricted port). | 8487 // port 80 (another restricted port). |
8487 http_server_properties->SetAlternateProtocol( | 8488 http_server_properties->AddAlternateProtocol( |
8488 HostPortPair::FromURL(request.url), | 8489 HostPortPair::FromURL(request.url), |
8489 666 /* port is ignored by MockConnect anyway */, | 8490 666 /* port is ignored by MockConnect anyway */, |
8490 AlternateProtocolFromNextProto(GetParam()), 1); | 8491 AlternateProtocolFromNextProto(GetParam()), 1); |
8491 | 8492 |
8492 scoped_ptr<HttpTransaction> trans( | 8493 scoped_ptr<HttpTransaction> trans( |
8493 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 8494 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
8494 TestCompletionCallback callback; | 8495 TestCompletionCallback callback; |
8495 | 8496 |
8496 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 8497 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
8497 EXPECT_EQ(ERR_IO_PENDING, rv); | 8498 EXPECT_EQ(ERR_IO_PENDING, rv); |
8498 EXPECT_EQ(OK, callback.WaitForResult()); | 8499 EXPECT_EQ(OK, callback.WaitForResult()); |
8499 | 8500 |
8500 const HttpResponseInfo* response = trans->GetResponseInfo(); | 8501 const HttpResponseInfo* response = trans->GetResponseInfo(); |
8501 ASSERT_TRUE(response != NULL); | 8502 ASSERT_TRUE(response != NULL); |
8502 ASSERT_TRUE(response->headers.get() != NULL); | 8503 ASSERT_TRUE(response->headers.get() != NULL); |
8503 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 8504 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
8504 | 8505 |
8505 std::string response_data; | 8506 std::string response_data; |
8506 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 8507 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
8507 EXPECT_EQ("hello world", response_data); | 8508 EXPECT_EQ("hello world", response_data); |
8508 | 8509 |
8509 ASSERT_TRUE(http_server_properties->HasAlternateProtocol( | 8510 ASSERT_TRUE(http_server_properties->HasAlternateProtocol( |
8510 HostPortPair::FromURL(request.url))); | 8511 HostPortPair::FromURL(request.url))); |
8511 const AlternateProtocolInfo alternate = | 8512 const AlternateProtocols alternate_protocols = |
8512 http_server_properties->GetAlternateProtocol( | 8513 http_server_properties->GetAlternateProtocols( |
8513 HostPortPair::FromURL(request.url)); | 8514 HostPortPair::FromURL(request.url)); |
| 8515 ASSERT_EQ(1u, alternate_protocols.size()); |
| 8516 const AlternateProtocolInfo alternate = alternate_protocols[0]; |
8514 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); | 8517 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); |
8515 } | 8518 } |
8516 | 8519 |
8517 TEST_P(HttpNetworkTransactionTest, | 8520 TEST_P(HttpNetworkTransactionTest, |
8518 AlternateProtocolPortRestrictedBlocked) { | 8521 AlternateProtocolPortRestrictedBlocked) { |
8519 // Ensure that we're not allowed to redirect traffic via an alternate | 8522 // Ensure that we're not allowed to redirect traffic via an alternate |
8520 // protocol to an unrestricted (port >= 1024) when the original traffic was | 8523 // protocol to an unrestricted (port >= 1024) when the original traffic was |
8521 // on a restricted port (port < 1024). Ensure that we can redirect in all | 8524 // on a restricted port (port < 1024). Ensure that we can redirect in all |
8522 // other cases. | 8525 // other cases. |
8523 session_deps_.use_alternate_protocols = true; | 8526 session_deps_.use_alternate_protocols = true; |
(...skipping 15 matching lines...) Expand all Loading... |
8539 }; | 8542 }; |
8540 StaticSocketDataProvider second_data( | 8543 StaticSocketDataProvider second_data( |
8541 data_reads, arraysize(data_reads), NULL, 0); | 8544 data_reads, arraysize(data_reads), NULL, 0); |
8542 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | 8545 session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
8543 | 8546 |
8544 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 8547 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
8545 | 8548 |
8546 base::WeakPtr<HttpServerProperties> http_server_properties = | 8549 base::WeakPtr<HttpServerProperties> http_server_properties = |
8547 session->http_server_properties(); | 8550 session->http_server_properties(); |
8548 const int kUnrestrictedAlternatePort = 1024; | 8551 const int kUnrestrictedAlternatePort = 1024; |
8549 http_server_properties->SetAlternateProtocol( | 8552 http_server_properties->AddAlternateProtocol( |
8550 HostPortPair::FromURL(restricted_port_request.url), | 8553 HostPortPair::FromURL(restricted_port_request.url), |
8551 kUnrestrictedAlternatePort, | 8554 kUnrestrictedAlternatePort, |
8552 AlternateProtocolFromNextProto(GetParam()), 1); | 8555 AlternateProtocolFromNextProto(GetParam()), 1); |
8553 | 8556 |
8554 scoped_ptr<HttpTransaction> trans( | 8557 scoped_ptr<HttpTransaction> trans( |
8555 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 8558 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
8556 TestCompletionCallback callback; | 8559 TestCompletionCallback callback; |
8557 | 8560 |
8558 int rv = trans->Start( | 8561 int rv = trans->Start( |
8559 &restricted_port_request, | 8562 &restricted_port_request, |
(...skipping 30 matching lines...) Expand all Loading... |
8590 }; | 8593 }; |
8591 StaticSocketDataProvider second_data( | 8594 StaticSocketDataProvider second_data( |
8592 data_reads, arraysize(data_reads), NULL, 0); | 8595 data_reads, arraysize(data_reads), NULL, 0); |
8593 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | 8596 session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
8594 | 8597 |
8595 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 8598 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
8596 | 8599 |
8597 base::WeakPtr<HttpServerProperties> http_server_properties = | 8600 base::WeakPtr<HttpServerProperties> http_server_properties = |
8598 session->http_server_properties(); | 8601 session->http_server_properties(); |
8599 const int kUnrestrictedAlternatePort = 1024; | 8602 const int kUnrestrictedAlternatePort = 1024; |
8600 http_server_properties->SetAlternateProtocol( | 8603 http_server_properties->AddAlternateProtocol( |
8601 HostPortPair::FromURL(restricted_port_request.url), | 8604 HostPortPair::FromURL(restricted_port_request.url), |
8602 kUnrestrictedAlternatePort, | 8605 kUnrestrictedAlternatePort, |
8603 AlternateProtocolFromNextProto(GetParam()), 1); | 8606 AlternateProtocolFromNextProto(GetParam()), 1); |
8604 | 8607 |
8605 scoped_ptr<HttpTransaction> trans( | 8608 scoped_ptr<HttpTransaction> trans( |
8606 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 8609 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
8607 TestCompletionCallback callback; | 8610 TestCompletionCallback callback; |
8608 | 8611 |
8609 EXPECT_EQ(ERR_IO_PENDING, trans->Start( | 8612 EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
8610 &restricted_port_request, | 8613 &restricted_port_request, |
(...skipping 27 matching lines...) Expand all Loading... |
8638 }; | 8641 }; |
8639 StaticSocketDataProvider second_data( | 8642 StaticSocketDataProvider second_data( |
8640 data_reads, arraysize(data_reads), NULL, 0); | 8643 data_reads, arraysize(data_reads), NULL, 0); |
8641 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | 8644 session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
8642 | 8645 |
8643 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 8646 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
8644 | 8647 |
8645 base::WeakPtr<HttpServerProperties> http_server_properties = | 8648 base::WeakPtr<HttpServerProperties> http_server_properties = |
8646 session->http_server_properties(); | 8649 session->http_server_properties(); |
8647 const int kRestrictedAlternatePort = 80; | 8650 const int kRestrictedAlternatePort = 80; |
8648 http_server_properties->SetAlternateProtocol( | 8651 http_server_properties->AddAlternateProtocol( |
8649 HostPortPair::FromURL(restricted_port_request.url), | 8652 HostPortPair::FromURL(restricted_port_request.url), |
8650 kRestrictedAlternatePort, | 8653 kRestrictedAlternatePort, |
8651 AlternateProtocolFromNextProto(GetParam()), 1); | 8654 AlternateProtocolFromNextProto(GetParam()), 1); |
8652 | 8655 |
8653 scoped_ptr<HttpTransaction> trans( | 8656 scoped_ptr<HttpTransaction> trans( |
8654 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 8657 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
8655 TestCompletionCallback callback; | 8658 TestCompletionCallback callback; |
8656 | 8659 |
8657 int rv = trans->Start( | 8660 int rv = trans->Start( |
8658 &restricted_port_request, | 8661 &restricted_port_request, |
(...skipping 28 matching lines...) Expand all Loading... |
8687 }; | 8690 }; |
8688 StaticSocketDataProvider second_data( | 8691 StaticSocketDataProvider second_data( |
8689 data_reads, arraysize(data_reads), NULL, 0); | 8692 data_reads, arraysize(data_reads), NULL, 0); |
8690 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | 8693 session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
8691 | 8694 |
8692 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 8695 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
8693 | 8696 |
8694 base::WeakPtr<HttpServerProperties> http_server_properties = | 8697 base::WeakPtr<HttpServerProperties> http_server_properties = |
8695 session->http_server_properties(); | 8698 session->http_server_properties(); |
8696 const int kRestrictedAlternatePort = 80; | 8699 const int kRestrictedAlternatePort = 80; |
8697 http_server_properties->SetAlternateProtocol( | 8700 http_server_properties->AddAlternateProtocol( |
8698 HostPortPair::FromURL(unrestricted_port_request.url), | 8701 HostPortPair::FromURL(unrestricted_port_request.url), |
8699 kRestrictedAlternatePort, | 8702 kRestrictedAlternatePort, |
8700 AlternateProtocolFromNextProto(GetParam()), 1); | 8703 AlternateProtocolFromNextProto(GetParam()), 1); |
8701 | 8704 |
8702 scoped_ptr<HttpTransaction> trans( | 8705 scoped_ptr<HttpTransaction> trans( |
8703 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 8706 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
8704 TestCompletionCallback callback; | 8707 TestCompletionCallback callback; |
8705 | 8708 |
8706 int rv = trans->Start( | 8709 int rv = trans->Start( |
8707 &unrestricted_port_request, callback.callback(), BoundNetLog()); | 8710 &unrestricted_port_request, callback.callback(), BoundNetLog()); |
(...skipping 27 matching lines...) Expand all Loading... |
8735 }; | 8738 }; |
8736 StaticSocketDataProvider second_data( | 8739 StaticSocketDataProvider second_data( |
8737 data_reads, arraysize(data_reads), NULL, 0); | 8740 data_reads, arraysize(data_reads), NULL, 0); |
8738 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | 8741 session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
8739 | 8742 |
8740 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 8743 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
8741 | 8744 |
8742 base::WeakPtr<HttpServerProperties> http_server_properties = | 8745 base::WeakPtr<HttpServerProperties> http_server_properties = |
8743 session->http_server_properties(); | 8746 session->http_server_properties(); |
8744 const int kUnrestrictedAlternatePort = 1024; | 8747 const int kUnrestrictedAlternatePort = 1024; |
8745 http_server_properties->SetAlternateProtocol( | 8748 http_server_properties->AddAlternateProtocol( |
8746 HostPortPair::FromURL(unrestricted_port_request.url), | 8749 HostPortPair::FromURL(unrestricted_port_request.url), |
8747 kUnrestrictedAlternatePort, | 8750 kUnrestrictedAlternatePort, |
8748 AlternateProtocolFromNextProto(GetParam()), 1); | 8751 AlternateProtocolFromNextProto(GetParam()), 1); |
8749 | 8752 |
8750 scoped_ptr<HttpTransaction> trans( | 8753 scoped_ptr<HttpTransaction> trans( |
8751 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 8754 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
8752 TestCompletionCallback callback; | 8755 TestCompletionCallback callback; |
8753 | 8756 |
8754 int rv = trans->Start( | 8757 int rv = trans->Start( |
8755 &unrestricted_port_request, callback.callback(), BoundNetLog()); | 8758 &unrestricted_port_request, callback.callback(), BoundNetLog()); |
(...skipping 22 matching lines...) Expand all Loading... |
8778 }; | 8781 }; |
8779 StaticSocketDataProvider data( | 8782 StaticSocketDataProvider data( |
8780 data_reads, arraysize(data_reads), NULL, 0); | 8783 data_reads, arraysize(data_reads), NULL, 0); |
8781 session_deps_.socket_factory->AddSocketDataProvider(&data); | 8784 session_deps_.socket_factory->AddSocketDataProvider(&data); |
8782 | 8785 |
8783 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 8786 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
8784 | 8787 |
8785 base::WeakPtr<HttpServerProperties> http_server_properties = | 8788 base::WeakPtr<HttpServerProperties> http_server_properties = |
8786 session->http_server_properties(); | 8789 session->http_server_properties(); |
8787 const int kUnsafePort = 7; | 8790 const int kUnsafePort = 7; |
8788 http_server_properties->SetAlternateProtocol( | 8791 http_server_properties->AddAlternateProtocol( |
8789 HostPortPair::FromURL(request.url), | 8792 HostPortPair::FromURL(request.url), |
8790 kUnsafePort, | 8793 kUnsafePort, |
8791 AlternateProtocolFromNextProto(GetParam()), 1); | 8794 AlternateProtocolFromNextProto(GetParam()), 1); |
8792 | 8795 |
8793 scoped_ptr<HttpTransaction> trans( | 8796 scoped_ptr<HttpTransaction> trans( |
8794 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 8797 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
8795 TestCompletionCallback callback; | 8798 TestCompletionCallback callback; |
8796 | 8799 |
8797 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 8800 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
8798 EXPECT_EQ(ERR_IO_PENDING, rv); | 8801 EXPECT_EQ(ERR_IO_PENDING, rv); |
(...skipping 4378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13177 EXPECT_EQ(ERR_IO_PENDING, rv); | 13180 EXPECT_EQ(ERR_IO_PENDING, rv); |
13178 | 13181 |
13179 rv = callback.WaitForResult(); | 13182 rv = callback.WaitForResult(); |
13180 EXPECT_EQ(ERR_CONNECTION_RESET, rv); | 13183 EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
13181 | 13184 |
13182 const HttpResponseInfo* response = trans->GetResponseInfo(); | 13185 const HttpResponseInfo* response = trans->GetResponseInfo(); |
13183 EXPECT_TRUE(response == NULL); | 13186 EXPECT_TRUE(response == NULL); |
13184 } | 13187 } |
13185 | 13188 |
13186 } // namespace net | 13189 } // namespace net |
OLD | NEW |