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 8767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8778 MockRead(ASYNC, OK), | 8778 MockRead(ASYNC, OK), |
8779 }; | 8779 }; |
8780 StaticSocketDataProvider second_data( | 8780 StaticSocketDataProvider second_data( |
8781 data_reads, arraysize(data_reads), NULL, 0); | 8781 data_reads, arraysize(data_reads), NULL, 0); |
8782 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | 8782 session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
8783 | 8783 |
8784 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 8784 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
8785 | 8785 |
8786 base::WeakPtr<HttpServerProperties> http_server_properties = | 8786 base::WeakPtr<HttpServerProperties> http_server_properties = |
8787 session->http_server_properties(); | 8787 session->http_server_properties(); |
| 8788 const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
8788 // Port must be < 1024, or the header will be ignored (since initial port was | 8789 // Port must be < 1024, or the header will be ignored (since initial port was |
8789 // port 80 (another restricted port). | 8790 // port 80 (another restricted port). |
8790 http_server_properties->SetAlternateProtocol( | 8791 http_server_properties->SetAlternateProtocol( |
8791 HostPortPair::FromURL(request.url), | 8792 host_port_pair, 666 /* port is ignored by MockConnect anyway */, |
8792 666 /* port is ignored by MockConnect anyway */, | |
8793 AlternateProtocolFromNextProto(GetParam()), 1.0); | 8793 AlternateProtocolFromNextProto(GetParam()), 1.0); |
8794 | 8794 |
8795 scoped_ptr<HttpTransaction> trans( | 8795 scoped_ptr<HttpTransaction> trans( |
8796 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 8796 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
8797 TestCompletionCallback callback; | 8797 TestCompletionCallback callback; |
8798 | 8798 |
8799 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 8799 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
8800 EXPECT_EQ(ERR_IO_PENDING, rv); | 8800 EXPECT_EQ(ERR_IO_PENDING, rv); |
8801 EXPECT_EQ(OK, callback.WaitForResult()); | 8801 EXPECT_EQ(OK, callback.WaitForResult()); |
8802 | 8802 |
8803 const HttpResponseInfo* response = trans->GetResponseInfo(); | 8803 const HttpResponseInfo* response = trans->GetResponseInfo(); |
8804 ASSERT_TRUE(response != NULL); | 8804 ASSERT_TRUE(response != NULL); |
8805 ASSERT_TRUE(response->headers.get() != NULL); | 8805 ASSERT_TRUE(response->headers.get() != NULL); |
8806 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 8806 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
8807 | 8807 |
8808 std::string response_data; | 8808 std::string response_data; |
8809 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 8809 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
8810 EXPECT_EQ("hello world", response_data); | 8810 EXPECT_EQ("hello world", response_data); |
8811 | 8811 |
8812 const AlternateProtocolInfo alternate = | 8812 const AlternateProtocolInfo alternate = |
8813 http_server_properties->GetAlternateProtocol( | 8813 http_server_properties->GetAlternateProtocol(host_port_pair); |
8814 HostPortPair::FromURL(request.url)); | |
8815 EXPECT_NE(UNINITIALIZED_ALTERNATE_PROTOCOL, alternate.protocol); | 8814 EXPECT_NE(UNINITIALIZED_ALTERNATE_PROTOCOL, alternate.protocol); |
8816 EXPECT_TRUE(alternate.is_broken); | 8815 const AlternativeService alternative_service( |
| 8816 alternate.protocol, host_port_pair.host(), alternate.port); |
| 8817 EXPECT_TRUE( |
| 8818 http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
8817 } | 8819 } |
8818 | 8820 |
8819 TEST_P(HttpNetworkTransactionTest, | 8821 TEST_P(HttpNetworkTransactionTest, |
8820 AlternateProtocolPortRestrictedBlocked) { | 8822 AlternateProtocolPortRestrictedBlocked) { |
8821 // Ensure that we're not allowed to redirect traffic via an alternate | 8823 // Ensure that we're not allowed to redirect traffic via an alternate |
8822 // protocol to an unrestricted (port >= 1024) when the original traffic was | 8824 // protocol to an unrestricted (port >= 1024) when the original traffic was |
8823 // on a restricted port (port < 1024). Ensure that we can redirect in all | 8825 // on a restricted port (port < 1024). Ensure that we can redirect in all |
8824 // other cases. | 8826 // other cases. |
8825 session_deps_.use_alternate_protocols = true; | 8827 session_deps_.use_alternate_protocols = true; |
8826 | 8828 |
(...skipping 4953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13780 ASSERT_TRUE(response); | 13782 ASSERT_TRUE(response); |
13781 ASSERT_TRUE(response->headers.get()); | 13783 ASSERT_TRUE(response->headers.get()); |
13782 | 13784 |
13783 EXPECT_EQ(101, response->headers->response_code()); | 13785 EXPECT_EQ(101, response->headers->response_code()); |
13784 | 13786 |
13785 trans.reset(); | 13787 trans.reset(); |
13786 session->CloseAllConnections(); | 13788 session->CloseAllConnections(); |
13787 } | 13789 } |
13788 | 13790 |
13789 } // namespace net | 13791 } // namespace net |
OLD | NEW |