| 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 7822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7833 bool ssl; | 7833 bool ssl; |
| 7834 }; | 7834 }; |
| 7835 | 7835 |
| 7836 scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( | 7836 scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
| 7837 NextProto next_proto, | 7837 NextProto next_proto, |
| 7838 SpdySessionDependencies* session_deps_) { | 7838 SpdySessionDependencies* session_deps_) { |
| 7839 scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); | 7839 scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
| 7840 | 7840 |
| 7841 base::WeakPtr<HttpServerProperties> http_server_properties = | 7841 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 7842 session->http_server_properties(); | 7842 session->http_server_properties(); |
| 7843 http_server_properties->SetAlternateProtocol( | 7843 AlternativeService alternative_service( |
| 7844 HostPortPair("host.with.alternate", 80), 443, | 7844 AlternateProtocolFromNextProto(next_proto), "alternative.host", 443); |
| 7845 AlternateProtocolFromNextProto(next_proto), 1.0); | 7845 http_server_properties->SetAlternativeService( |
| 7846 HostPortPair("host.with.alternate", 80), alternative_service, 1.0); |
| 7846 | 7847 |
| 7847 return session; | 7848 return session; |
| 7848 } | 7849 } |
| 7849 | 7850 |
| 7850 int GroupNameTransactionHelper( | 7851 int GroupNameTransactionHelper( |
| 7851 const std::string& url, | 7852 const std::string& url, |
| 7852 const scoped_refptr<HttpNetworkSession>& session) { | 7853 const scoped_refptr<HttpNetworkSession>& session) { |
| 7853 HttpRequestInfo request; | 7854 HttpRequestInfo request; |
| 7854 request.method = "GET"; | 7855 request.method = "GET"; |
| 7855 request.url = GURL(url); | 7856 request.url = GURL(url); |
| (...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8781 data_reads, arraysize(data_reads), NULL, 0); | 8782 data_reads, arraysize(data_reads), NULL, 0); |
| 8782 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | 8783 session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 8783 | 8784 |
| 8784 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 8785 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8785 | 8786 |
| 8786 base::WeakPtr<HttpServerProperties> http_server_properties = | 8787 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 8787 session->http_server_properties(); | 8788 session->http_server_properties(); |
| 8788 const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); | 8789 const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
| 8789 // Port must be < 1024, or the header will be ignored (since initial port was | 8790 // Port must be < 1024, or the header will be ignored (since initial port was |
| 8790 // port 80 (another restricted port). | 8791 // port 80 (another restricted port). |
| 8791 http_server_properties->SetAlternateProtocol( | 8792 AlternativeService alternative_service( |
| 8792 host_port_pair, 666 /* port is ignored by MockConnect anyway */, | 8793 AlternateProtocolFromNextProto(GetParam()), "www.google.com", |
| 8793 AlternateProtocolFromNextProto(GetParam()), 1.0); | 8794 666); /* port is ignored by MockConnect anyway */ |
| 8795 http_server_properties->SetAlternativeService(host_port_pair, |
| 8796 alternative_service, 1.0); |
| 8794 | 8797 |
| 8795 scoped_ptr<HttpTransaction> trans( | 8798 scoped_ptr<HttpTransaction> trans( |
| 8796 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 8799 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8797 TestCompletionCallback callback; | 8800 TestCompletionCallback callback; |
| 8798 | 8801 |
| 8799 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 8802 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8800 EXPECT_EQ(ERR_IO_PENDING, rv); | 8803 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8801 EXPECT_EQ(OK, callback.WaitForResult()); | 8804 EXPECT_EQ(OK, callback.WaitForResult()); |
| 8802 | 8805 |
| 8803 const HttpResponseInfo* response = trans->GetResponseInfo(); | 8806 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8804 ASSERT_TRUE(response != NULL); | 8807 ASSERT_TRUE(response != NULL); |
| 8805 ASSERT_TRUE(response->headers.get() != NULL); | 8808 ASSERT_TRUE(response->headers.get() != NULL); |
| 8806 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 8809 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8807 | 8810 |
| 8808 std::string response_data; | 8811 std::string response_data; |
| 8809 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 8812 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8810 EXPECT_EQ("hello world", response_data); | 8813 EXPECT_EQ("hello world", response_data); |
| 8811 | 8814 |
| 8812 const AlternativeService alternative_service = | 8815 alternative_service = |
| 8813 http_server_properties->GetAlternativeService(host_port_pair); | 8816 http_server_properties->GetAlternativeService(host_port_pair); |
| 8814 EXPECT_NE(UNINITIALIZED_ALTERNATE_PROTOCOL, alternative_service.protocol); | 8817 EXPECT_NE(UNINITIALIZED_ALTERNATE_PROTOCOL, alternative_service.protocol); |
| 8815 EXPECT_TRUE( | 8818 EXPECT_TRUE( |
| 8816 http_server_properties->IsAlternativeServiceBroken(alternative_service)); | 8819 http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 8817 } | 8820 } |
| 8818 | 8821 |
| 8819 TEST_P(HttpNetworkTransactionTest, | 8822 TEST_P(HttpNetworkTransactionTest, |
| 8820 AlternateProtocolPortRestrictedBlocked) { | 8823 AlternateProtocolPortRestrictedBlocked) { |
| 8821 // Ensure that we're not allowed to redirect traffic via an alternate | 8824 // Ensure that we're not allowed to redirect traffic via an alternate |
| 8822 // protocol to an unrestricted (port >= 1024) when the original traffic was | 8825 // protocol to an unrestricted (port >= 1024) when the original traffic was |
| (...skipping 18 matching lines...) Expand all Loading... |
| 8841 }; | 8844 }; |
| 8842 StaticSocketDataProvider second_data( | 8845 StaticSocketDataProvider second_data( |
| 8843 data_reads, arraysize(data_reads), NULL, 0); | 8846 data_reads, arraysize(data_reads), NULL, 0); |
| 8844 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | 8847 session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 8845 | 8848 |
| 8846 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 8849 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8847 | 8850 |
| 8848 base::WeakPtr<HttpServerProperties> http_server_properties = | 8851 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 8849 session->http_server_properties(); | 8852 session->http_server_properties(); |
| 8850 const int kUnrestrictedAlternatePort = 1024; | 8853 const int kUnrestrictedAlternatePort = 1024; |
| 8851 http_server_properties->SetAlternateProtocol( | 8854 AlternativeService alternative_service( |
| 8852 HostPortPair::FromURL(restricted_port_request.url), | 8855 AlternateProtocolFromNextProto(GetParam()), "www.google.com", |
| 8853 kUnrestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()), | 8856 kUnrestrictedAlternatePort); |
| 8857 http_server_properties->SetAlternativeService( |
| 8858 HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
| 8854 1.0); | 8859 1.0); |
| 8855 | 8860 |
| 8856 scoped_ptr<HttpTransaction> trans( | 8861 scoped_ptr<HttpTransaction> trans( |
| 8857 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 8862 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8858 TestCompletionCallback callback; | 8863 TestCompletionCallback callback; |
| 8859 | 8864 |
| 8860 int rv = trans->Start( | 8865 int rv = trans->Start( |
| 8861 &restricted_port_request, | 8866 &restricted_port_request, |
| 8862 callback.callback(), BoundNetLog()); | 8867 callback.callback(), BoundNetLog()); |
| 8863 EXPECT_EQ(ERR_IO_PENDING, rv); | 8868 EXPECT_EQ(ERR_IO_PENDING, rv); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 8892 }; | 8897 }; |
| 8893 StaticSocketDataProvider second_data( | 8898 StaticSocketDataProvider second_data( |
| 8894 data_reads, arraysize(data_reads), NULL, 0); | 8899 data_reads, arraysize(data_reads), NULL, 0); |
| 8895 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | 8900 session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 8896 | 8901 |
| 8897 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 8902 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8898 | 8903 |
| 8899 base::WeakPtr<HttpServerProperties> http_server_properties = | 8904 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 8900 session->http_server_properties(); | 8905 session->http_server_properties(); |
| 8901 const int kUnrestrictedAlternatePort = 1024; | 8906 const int kUnrestrictedAlternatePort = 1024; |
| 8902 http_server_properties->SetAlternateProtocol( | 8907 AlternativeService alternative_service( |
| 8903 HostPortPair::FromURL(restricted_port_request.url), | 8908 AlternateProtocolFromNextProto(GetParam()), "www.google.com", |
| 8904 kUnrestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()), | 8909 kUnrestrictedAlternatePort); |
| 8910 http_server_properties->SetAlternativeService( |
| 8911 HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
| 8905 1.0); | 8912 1.0); |
| 8906 | 8913 |
| 8907 scoped_ptr<HttpTransaction> trans( | 8914 scoped_ptr<HttpTransaction> trans( |
| 8908 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 8915 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8909 TestCompletionCallback callback; | 8916 TestCompletionCallback callback; |
| 8910 | 8917 |
| 8911 EXPECT_EQ(ERR_IO_PENDING, trans->Start( | 8918 EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
| 8912 &restricted_port_request, | 8919 &restricted_port_request, |
| 8913 callback.callback(), BoundNetLog())); | 8920 callback.callback(), BoundNetLog())); |
| 8914 // Change to unrestricted port should succeed. | 8921 // Change to unrestricted port should succeed. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 8940 }; | 8947 }; |
| 8941 StaticSocketDataProvider second_data( | 8948 StaticSocketDataProvider second_data( |
| 8942 data_reads, arraysize(data_reads), NULL, 0); | 8949 data_reads, arraysize(data_reads), NULL, 0); |
| 8943 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | 8950 session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 8944 | 8951 |
| 8945 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 8952 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8946 | 8953 |
| 8947 base::WeakPtr<HttpServerProperties> http_server_properties = | 8954 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 8948 session->http_server_properties(); | 8955 session->http_server_properties(); |
| 8949 const int kRestrictedAlternatePort = 80; | 8956 const int kRestrictedAlternatePort = 80; |
| 8950 http_server_properties->SetAlternateProtocol( | 8957 AlternativeService alternative_service( |
| 8951 HostPortPair::FromURL(restricted_port_request.url), | 8958 AlternateProtocolFromNextProto(GetParam()), "www.google.com", |
| 8952 kRestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()), | 8959 kRestrictedAlternatePort); |
| 8960 http_server_properties->SetAlternativeService( |
| 8961 HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
| 8953 1.0); | 8962 1.0); |
| 8954 | 8963 |
| 8955 scoped_ptr<HttpTransaction> trans( | 8964 scoped_ptr<HttpTransaction> trans( |
| 8956 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 8965 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8957 TestCompletionCallback callback; | 8966 TestCompletionCallback callback; |
| 8958 | 8967 |
| 8959 int rv = trans->Start( | 8968 int rv = trans->Start( |
| 8960 &restricted_port_request, | 8969 &restricted_port_request, |
| 8961 callback.callback(), BoundNetLog()); | 8970 callback.callback(), BoundNetLog()); |
| 8962 EXPECT_EQ(ERR_IO_PENDING, rv); | 8971 EXPECT_EQ(ERR_IO_PENDING, rv); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 8989 }; | 8998 }; |
| 8990 StaticSocketDataProvider second_data( | 8999 StaticSocketDataProvider second_data( |
| 8991 data_reads, arraysize(data_reads), NULL, 0); | 9000 data_reads, arraysize(data_reads), NULL, 0); |
| 8992 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | 9001 session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 8993 | 9002 |
| 8994 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 9003 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8995 | 9004 |
| 8996 base::WeakPtr<HttpServerProperties> http_server_properties = | 9005 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 8997 session->http_server_properties(); | 9006 session->http_server_properties(); |
| 8998 const int kRestrictedAlternatePort = 80; | 9007 const int kRestrictedAlternatePort = 80; |
| 8999 http_server_properties->SetAlternateProtocol( | 9008 AlternativeService alternative_service( |
| 9000 HostPortPair::FromURL(unrestricted_port_request.url), | 9009 AlternateProtocolFromNextProto(GetParam()), "www.google.com", |
| 9001 kRestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()), | 9010 kRestrictedAlternatePort); |
| 9011 http_server_properties->SetAlternativeService( |
| 9012 HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
| 9002 1.0); | 9013 1.0); |
| 9003 | 9014 |
| 9004 scoped_ptr<HttpTransaction> trans( | 9015 scoped_ptr<HttpTransaction> trans( |
| 9005 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 9016 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9006 TestCompletionCallback callback; | 9017 TestCompletionCallback callback; |
| 9007 | 9018 |
| 9008 int rv = trans->Start( | 9019 int rv = trans->Start( |
| 9009 &unrestricted_port_request, callback.callback(), BoundNetLog()); | 9020 &unrestricted_port_request, callback.callback(), BoundNetLog()); |
| 9010 EXPECT_EQ(ERR_IO_PENDING, rv); | 9021 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9011 // Valid change to restricted port should pass. | 9022 // Valid change to restricted port should pass. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 9037 }; | 9048 }; |
| 9038 StaticSocketDataProvider second_data( | 9049 StaticSocketDataProvider second_data( |
| 9039 data_reads, arraysize(data_reads), NULL, 0); | 9050 data_reads, arraysize(data_reads), NULL, 0); |
| 9040 session_deps_.socket_factory->AddSocketDataProvider(&second_data); | 9051 session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 9041 | 9052 |
| 9042 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 9053 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9043 | 9054 |
| 9044 base::WeakPtr<HttpServerProperties> http_server_properties = | 9055 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 9045 session->http_server_properties(); | 9056 session->http_server_properties(); |
| 9046 const int kUnrestrictedAlternatePort = 1024; | 9057 const int kUnrestrictedAlternatePort = 1024; |
| 9047 http_server_properties->SetAlternateProtocol( | 9058 AlternativeService alternative_service( |
| 9048 HostPortPair::FromURL(unrestricted_port_request.url), | 9059 AlternateProtocolFromNextProto(GetParam()), "www.google.com", |
| 9049 kUnrestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()), | 9060 kUnrestrictedAlternatePort); |
| 9061 http_server_properties->SetAlternativeService( |
| 9062 HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
| 9050 1.0); | 9063 1.0); |
| 9051 | 9064 |
| 9052 scoped_ptr<HttpTransaction> trans( | 9065 scoped_ptr<HttpTransaction> trans( |
| 9053 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 9066 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9054 TestCompletionCallback callback; | 9067 TestCompletionCallback callback; |
| 9055 | 9068 |
| 9056 int rv = trans->Start( | 9069 int rv = trans->Start( |
| 9057 &unrestricted_port_request, callback.callback(), BoundNetLog()); | 9070 &unrestricted_port_request, callback.callback(), BoundNetLog()); |
| 9058 EXPECT_EQ(ERR_IO_PENDING, rv); | 9071 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9059 // Valid change to an unrestricted port should pass. | 9072 // Valid change to an unrestricted port should pass. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 9080 }; | 9093 }; |
| 9081 StaticSocketDataProvider data( | 9094 StaticSocketDataProvider data( |
| 9082 data_reads, arraysize(data_reads), NULL, 0); | 9095 data_reads, arraysize(data_reads), NULL, 0); |
| 9083 session_deps_.socket_factory->AddSocketDataProvider(&data); | 9096 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9084 | 9097 |
| 9085 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 9098 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9086 | 9099 |
| 9087 base::WeakPtr<HttpServerProperties> http_server_properties = | 9100 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 9088 session->http_server_properties(); | 9101 session->http_server_properties(); |
| 9089 const int kUnsafePort = 7; | 9102 const int kUnsafePort = 7; |
| 9090 http_server_properties->SetAlternateProtocol( | 9103 AlternativeService alternative_service( |
| 9091 HostPortPair::FromURL(request.url), kUnsafePort, | 9104 AlternateProtocolFromNextProto(GetParam()), "www.google.com", |
| 9092 AlternateProtocolFromNextProto(GetParam()), 1.0); | 9105 kUnsafePort); |
| 9106 http_server_properties->SetAlternativeService( |
| 9107 HostPortPair::FromURL(request.url), alternative_service, 1.0); |
| 9093 | 9108 |
| 9094 scoped_ptr<HttpTransaction> trans( | 9109 scoped_ptr<HttpTransaction> trans( |
| 9095 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 9110 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9096 TestCompletionCallback callback; | 9111 TestCompletionCallback callback; |
| 9097 | 9112 |
| 9098 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 9113 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9099 EXPECT_EQ(ERR_IO_PENDING, rv); | 9114 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9100 // The HTTP request should succeed. | 9115 // The HTTP request should succeed. |
| 9101 EXPECT_EQ(OK, callback.WaitForResult()); | 9116 EXPECT_EQ(OK, callback.WaitForResult()); |
| 9102 | 9117 |
| (...skipping 4677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13780 ASSERT_TRUE(response); | 13795 ASSERT_TRUE(response); |
| 13781 ASSERT_TRUE(response->headers.get()); | 13796 ASSERT_TRUE(response->headers.get()); |
| 13782 | 13797 |
| 13783 EXPECT_EQ(101, response->headers->response_code()); | 13798 EXPECT_EQ(101, response->headers->response_code()); |
| 13784 | 13799 |
| 13785 trans.reset(); | 13800 trans.reset(); |
| 13786 session->CloseAllConnections(); | 13801 session->CloseAllConnections(); |
| 13787 } | 13802 } |
| 13788 | 13803 |
| 13789 } // namespace net | 13804 } // namespace net |
| OLD | NEW |