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 11953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11964 // The alternative service host must exhibit a certificate that is valid for the | 11964 // The alternative service host must exhibit a certificate that is valid for the |
11965 // origin host. Test that this is enforced when opening a new connection. | 11965 // origin host. Test that this is enforced when opening a new connection. |
11966 TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { | 11966 TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { |
11967 Run(false, true); | 11967 Run(false, true); |
11968 } | 11968 } |
11969 | 11969 |
11970 TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { | 11970 TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { |
11971 Run(false, false); | 11971 Run(false, false); |
11972 } | 11972 } |
11973 | 11973 |
11974 // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated | |
11975 // with the alternative server. That connection should not be used. | |
11976 TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { | |
11977 HostPortPair origin("origin.example.org", 443); | |
11978 HostPortPair alternative("alternative.example.org", 443); | |
11979 | |
11980 // Negotiate HTTP/1.1 with alternative.example.org. | |
11981 SSLSocketDataProvider ssl(ASYNC, OK); | |
11982 ssl.SetNextProto(kProtoHTTP11); | |
11983 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
11984 | |
11985 // No data should be read from the alternative, because HTTP/1.1 is | |
11986 // negotiated. | |
11987 StaticSocketDataProvider data; | |
11988 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
11989 | |
11990 // Connection to the origin fails. | |
11991 StaticSocketDataProvider data_refused; | |
11992 data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); | |
11993 session_deps_.socket_factory->AddSocketDataProvider(&data_refused); | |
11994 | |
11995 // Set up alternative service for origin. | |
11996 session_deps_.use_alternate_protocols = true; | |
11997 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
11998 base::WeakPtr<HttpServerProperties> http_server_properties = | |
11999 session->http_server_properties(); | |
12000 AlternativeService alternative_service( | |
12001 AlternateProtocolFromNextProto(GetParam()), alternative); | |
12002 http_server_properties->SetAlternativeService(origin, alternative_service, | |
12003 1.0); | |
12004 | |
12005 scoped_ptr<HttpTransaction> trans( | |
12006 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
12007 HttpRequestInfo request; | |
12008 request.method = "GET"; | |
12009 request.url = GURL("https://origin.example.org:443"); | |
12010 request.load_flags = 0; | |
12011 TestCompletionCallback callback; | |
12012 | |
12013 // HTTP/2 (or SPDY) is required for alternative service. | |
12014 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
12015 EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); | |
Ryan Hamilton
2015/05/05 20:51:12
It's not obvious to me that this should be user vi
Bence
2015/05/06 13:21:55
This test passes without landing the rest of this
Ryan Hamilton
2015/05/06 21:32:53
Landing this now is totally fine. I guess this all
Bence
2015/05/08 14:46:13
Yes, that's my understanding.
| |
12016 } | |
12017 | |
12018 // Alternative service requires HTTP/2 (or SPDY), but there is already a | |
12019 // HTTP/1.1 socket open to the alternative server. That socket should not be | |
12020 // used. | |
12021 TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { | |
12022 HostPortPair origin("origin.example.org", 443); | |
12023 HostPortPair alternative("alternative.example.org", 443); | |
12024 std::string origin_url = "https://origin.example.org:443"; | |
12025 std::string alternative_url = "https://alternative.example.org:443"; | |
12026 | |
12027 // Negotiate HTTP/1.1 with alternative.example.org. | |
12028 SSLSocketDataProvider ssl(ASYNC, OK); | |
12029 ssl.SetNextProto(kProtoHTTP11); | |
12030 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
12031 | |
12032 MockWrite http_writes[] = { | |
12033 MockWrite( | |
12034 "GET / HTTP/1.1\r\n" | |
12035 "Host: alternative.example.org\r\n" | |
12036 "Connection: keep-alive\r\n\r\n"), | |
12037 MockWrite( | |
12038 "GET / HTTP/1.1\r\n" | |
12039 "Host: alternative.example.org\r\n" | |
12040 "Connection: keep-alive\r\n\r\n"), | |
12041 }; | |
12042 | |
12043 MockRead http_reads[] = { | |
12044 MockRead( | |
12045 "HTTP/1.1 200 OK\r\n" | |
12046 "Content-Type: text/html; charset=iso-8859-1\r\n" | |
12047 "Content-Length: 40\r\n\r\n" | |
12048 "first HTTP/1.1 response from alternative"), | |
12049 MockRead( | |
12050 "HTTP/1.1 200 OK\r\n" | |
12051 "Content-Type: text/html; charset=iso-8859-1\r\n" | |
12052 "Content-Length: 41\r\n\r\n" | |
12053 "second HTTP/1.1 response from alternative"), | |
12054 }; | |
12055 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), | |
12056 http_writes, arraysize(http_writes)); | |
12057 session_deps_.socket_factory->AddSocketDataProvider(&http_data); | |
12058 | |
12059 // Connection to the origin fails. | |
12060 StaticSocketDataProvider data_refused; | |
12061 data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); | |
Ryan Hamilton
2015/05/05 20:51:12
I don't understand why this test sets connection r
Bence
2015/05/06 13:21:55
|request2| is to |origin|, which has an alternativ
Ryan Hamilton
2015/05/06 21:32:53
Mind adding a comment to this (and the previous) t
Bence
2015/05/08 14:46:13
Done.
Ryan Hamilton
2015/05/08 15:15:04
This would be testing that in the "normal" case, t
| |
12062 session_deps_.socket_factory->AddSocketDataProvider(&data_refused); | |
12063 | |
12064 // Set up alternative service for origin. | |
12065 session_deps_.use_alternate_protocols = true; | |
12066 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
12067 base::WeakPtr<HttpServerProperties> http_server_properties = | |
12068 session->http_server_properties(); | |
12069 AlternativeService alternative_service( | |
12070 AlternateProtocolFromNextProto(GetParam()), alternative); | |
12071 http_server_properties->SetAlternativeService(origin, alternative_service, | |
12072 1.0); | |
12073 | |
12074 // First transaction to alternative to open an HTTP/1.1 socket. | |
12075 scoped_ptr<HttpTransaction> trans1( | |
12076 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
12077 HttpRequestInfo request1; | |
12078 request1.method = "GET"; | |
12079 request1.url = GURL(alternative_url); | |
12080 request1.load_flags = 0; | |
12081 TestCompletionCallback callback1; | |
12082 | |
12083 int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); | |
12084 EXPECT_EQ(OK, callback1.GetResult(rv)); | |
12085 const HttpResponseInfo* response1 = trans1->GetResponseInfo(); | |
12086 ASSERT_TRUE(response1); | |
12087 ASSERT_TRUE(response1->headers.get()); | |
12088 EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); | |
12089 EXPECT_TRUE(response1->was_npn_negotiated); | |
12090 EXPECT_FALSE(response1->was_fetched_via_spdy); | |
12091 std::string response_data1; | |
12092 ASSERT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); | |
12093 EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); | |
12094 | |
12095 // Request for origin.example.org, which has an alternative service. This | |
12096 // will start two Jobs: the alternative should find the HTTP/1.1, ignore it, | |
12097 // but not open other connections to alternative. The Job to origin fails, | |
12098 // so this request fails. | |
12099 scoped_ptr<HttpTransaction> trans2( | |
12100 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
12101 HttpRequestInfo request2; | |
12102 request2.method = "GET"; | |
12103 request2.url = GURL(origin_url); | |
12104 request2.load_flags = 0; | |
12105 TestCompletionCallback callback2; | |
12106 | |
12107 rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); | |
12108 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback2.GetResult(rv)); | |
12109 | |
12110 // Another transaction to alternative. This is to test that the HTTP/1.1 | |
12111 // socket is still open and in the pool. | |
12112 scoped_ptr<HttpTransaction> trans3( | |
12113 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
12114 HttpRequestInfo request3; | |
12115 request3.method = "GET"; | |
12116 request3.url = GURL(alternative_url); | |
12117 request3.load_flags = 0; | |
12118 TestCompletionCallback callback3; | |
12119 | |
12120 rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); | |
12121 EXPECT_EQ(OK, callback3.GetResult(rv)); | |
12122 const HttpResponseInfo* response3 = trans3->GetResponseInfo(); | |
12123 ASSERT_TRUE(response3); | |
12124 ASSERT_TRUE(response3->headers.get()); | |
12125 EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); | |
12126 EXPECT_TRUE(response3->was_npn_negotiated); | |
12127 EXPECT_FALSE(response3->was_fetched_via_spdy); | |
12128 std::string response_data3; | |
12129 ASSERT_EQ(OK, ReadTransaction(trans3.get(), &response_data3)); | |
12130 EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); | |
12131 } | |
12132 | |
11974 TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { | 12133 TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
11975 const std::string https_url = "https://www.example.org:8080/"; | 12134 const std::string https_url = "https://www.example.org:8080/"; |
11976 const std::string http_url = "http://www.example.org:8080/"; | 12135 const std::string http_url = "http://www.example.org:8080/"; |
11977 | 12136 |
11978 // SPDY GET for HTTPS URL (through CONNECT tunnel) | 12137 // SPDY GET for HTTPS URL (through CONNECT tunnel) |
11979 const HostPortPair host_port_pair("www.example.org", 8080); | 12138 const HostPortPair host_port_pair("www.example.org", 8080); |
11980 scoped_ptr<SpdyFrame> connect( | 12139 scoped_ptr<SpdyFrame> connect( |
11981 spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); | 12140 spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
11982 scoped_ptr<SpdyFrame> req1( | 12141 scoped_ptr<SpdyFrame> req1( |
11983 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); | 12142 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
(...skipping 2022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14006 ASSERT_TRUE(response); | 14165 ASSERT_TRUE(response); |
14007 ASSERT_TRUE(response->headers.get()); | 14166 ASSERT_TRUE(response->headers.get()); |
14008 | 14167 |
14009 EXPECT_EQ(101, response->headers->response_code()); | 14168 EXPECT_EQ(101, response->headers->response_code()); |
14010 | 14169 |
14011 trans.reset(); | 14170 trans.reset(); |
14012 session->CloseAllConnections(); | 14171 session->CloseAllConnections(); |
14013 } | 14172 } |
14014 | 14173 |
14015 } // namespace net | 14174 } // namespace net |
OLD | NEW |