summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/base/run_all_unittests.cc3
-rw-r--r--net/http/http_network_transaction_unittest.cc54
-rw-r--r--net/http/http_stream_factory.cc3
-rw-r--r--net/http/http_stream_factory.h10
-rw-r--r--net/http/http_stream_request.cc13
5 files changed, 78 insertions, 5 deletions
diff --git a/net/base/run_all_unittests.cc b/net/base/run_all_unittests.cc
index 77f00f0..5f2207d 100644
--- a/net/base/run_all_unittests.cc
+++ b/net/base/run_all_unittests.cc
@@ -6,6 +6,7 @@
#include "base/histogram.h"
#include "base/nss_util.h"
#include "net/base/net_test_suite.h"
+#include "net/http/http_stream_factory.h"
#if defined(OS_WIN)
#include "net/socket/ssl_client_socket_nss_factory.h"
#endif
@@ -24,5 +25,7 @@ int main(int argc, char** argv) {
base::EnsureNSPRInit();
#endif
+ net::HttpStreamFactory::set_create_new_spdy_session_for_http(true);
+
return test_suite.Run();
}
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 02d4a5f..ca3caac 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -4833,7 +4833,6 @@ TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) {
"ssl/www.google.com:443",
true,
},
-
{
"http_proxy",
"http://host.with.alternate/direct",
@@ -4899,7 +4898,6 @@ TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) {
"socks5/ssl/www.google.com:443",
true,
},
-
{
"socks4://socks_proxy:1080",
"http://host.with.alternate/direct",
@@ -7410,4 +7408,56 @@ TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) {
EXPECT_EQ(OK, callback.WaitForResult());
}
+
+TEST_F(HttpNetworkTransactionTest, DoNotCreateSpdySessionForHttp) {
+ HttpStreamFactory::set_create_new_spdy_session_for_http(false);
+ HttpStreamFactory::set_use_alternate_protocols(true);
+ HttpStreamFactory::set_next_protos(kExpectedNPNString);
+
+ SessionDependencies session_deps;
+ HttpRequestInfo request;
+ request.method = "GET";
+ request.url = GURL("http://www.google.com/");
+ request.load_flags = 0;
+
+ MockRead data_reads[] = {
+ MockRead("HTTP/1.1 200 OK\r\n\r\n"),
+ MockRead("hello world"),
+ MockRead(true, OK),
+ };
+ StaticSocketDataProvider data(
+ data_reads, arraysize(data_reads), NULL, 0);
+ session_deps.socket_factory.AddSocketDataProvider(&data);
+
+ TestCompletionCallback callback;
+
+ scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
+
+ HostPortPair http_host_port_pair("www.google.com", 80);
+ HttpAlternateProtocols* alternate_protocols =
+ session->mutable_alternate_protocols();
+ alternate_protocols->SetAlternateProtocolFor(
+ http_host_port_pair, 443 /* port is ignored */,
+ HttpAlternateProtocols::NPN_SPDY_2);
+
+ scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
+
+ int rv = trans->Start(&request, &callback, BoundNetLog());
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+ EXPECT_EQ(OK, callback.WaitForResult());
+
+ const HttpResponseInfo* response = trans->GetResponseInfo();
+ ASSERT_TRUE(response != NULL);
+ ASSERT_TRUE(response->headers != NULL);
+ EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
+
+ std::string response_data;
+ ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
+ EXPECT_EQ("hello world", response_data);
+
+ HttpStreamFactory::set_next_protos("");
+ HttpStreamFactory::set_use_alternate_protocols(false);
+ HttpStreamFactory::set_create_new_spdy_session_for_http(true);
+}
+
} // namespace net
diff --git a/net/http/http_stream_factory.cc b/net/http/http_stream_factory.cc
index bbe2878..f471a4f 100644
--- a/net/http/http_stream_factory.cc
+++ b/net/http/http_stream_factory.cc
@@ -27,6 +27,8 @@ bool HttpStreamFactory::force_spdy_over_ssl_ = true;
bool HttpStreamFactory::force_spdy_always_ = false;
// static
bool HttpStreamFactory::ignore_certificate_errors_ = false;
+// static
+bool HttpStreamFactory::g_create_new_spdy_session_for_http_ = false;
// static
void HttpStreamFactory::SetHostMappingRules(const std::string& rules) {
@@ -138,4 +140,3 @@ GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url,
}
} // namespace net
-
diff --git a/net/http/http_stream_factory.h b/net/http/http_stream_factory.h
index 804ef35..db50038 100644
--- a/net/http/http_stream_factory.h
+++ b/net/http/http_stream_factory.h
@@ -89,6 +89,14 @@ class HttpStreamFactory : public StreamFactory,
return ignore_certificate_errors_;
}
+ static void set_create_new_spdy_session_for_http(bool value) {
+ g_create_new_spdy_session_for_http_ = value;
+ }
+
+ static bool create_new_spdy_session_for_http() {
+ return g_create_new_spdy_session_for_http_;
+ }
+
static void SetHostMappingRules(const std::string& rules);
private:
@@ -100,6 +108,7 @@ class HttpStreamFactory : public StreamFactory,
static bool force_spdy_over_ssl_;
static bool force_spdy_always_;
static bool ignore_certificate_errors_;
+ static bool g_create_new_spdy_session_for_http_;
DISALLOW_COPY_AND_ASSIGN(HttpStreamFactory);
};
@@ -107,4 +116,3 @@ class HttpStreamFactory : public StreamFactory,
} // namespace net
#endif // NET_HTTP_HTTP_STREAM_FACTORY_H_
-
diff --git a/net/http/http_stream_request.cc b/net/http/http_stream_request.cc
index 59a7e8c..35832c7 100644
--- a/net/http/http_stream_request.cc
+++ b/net/http/http_stream_request.cc
@@ -422,7 +422,18 @@ int HttpStreamRequest::DoResolveProxyComplete(int result) {
return ERR_NO_SUPPORTED_PROXIES;
}
- next_state_ = STATE_INIT_CONNECTION;
+ HostPortProxyPair pair(endpoint_, proxy_info()->proxy_server());
+ if (!factory_->create_new_spdy_session_for_http() &&
+ alternate_protocol_mode_ == kUsingAlternateProtocol &&
+ !session_->spdy_session_pool()->HasSession(pair)) {
+ // If we don't already have a SpdySession, then don't pay the SSL handshake
+ // cost of setup. Just use HTTP.
+ next_state_ = STATE_RESOLVE_PROXY;
+ alternate_protocol_mode_ = kDoNotUseAlternateProtocol;
+ } else {
+ next_state_ = STATE_INIT_CONNECTION;
+ }
+
return OK;
}