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