Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Side by Side Diff: net/http/http_network_layer.cc

Issue 8156001: net: rework the NPN patch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_layer.h" 5 #include "net/http/http_network_layer.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/string_split.h" 9 #include "base/string_split.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // We want an A/B experiment between SPDY enabled and SPDY disabled, 57 // We want an A/B experiment between SPDY enabled and SPDY disabled,
58 // but only for pages where SPDY *could have been* negotiated. To do 58 // but only for pages where SPDY *could have been* negotiated. To do
59 // this, we use NPN, but prevent it from negotiating SPDY. If the 59 // this, we use NPN, but prevent it from negotiating SPDY. If the
60 // server negotiates HTTP, rather than SPDY, today that will only happen 60 // server negotiates HTTP, rather than SPDY, today that will only happen
61 // on servers that installed NPN (and could have done SPDY). But this is 61 // on servers that installed NPN (and could have done SPDY). But this is
62 // a bit of a hack, as this correlation between NPN and SPDY is not 62 // a bit of a hack, as this correlation between NPN and SPDY is not
63 // really guaranteed. 63 // really guaranteed.
64 static const char kEnableNPN[] = "npn"; 64 static const char kEnableNPN[] = "npn";
65 static const char kEnableNpnHttpOnly[] = "npn-http"; 65 static const char kEnableNpnHttpOnly[] = "npn-http";
66 66
67 // Except for the first element, the order is irrelevant. First element
68 // specifies the fallback in case nothing matches
69 // (SSLClientSocket::kNextProtoNoOverlap). Otherwise, the SSL library
70 // will choose the first overlapping protocol in the server's list, since
71 // it presumedly has a better understanding of which protocol we should
72 // use, therefore the rest of the ordering here is not important.
73 static const char kNpnProtosFull[] = "\x08http/1.1\x06spdy/2";
74 // This is a temporary hack to pretend we support version 1.
wtc 2011/10/11 23:43:04 Nit: it seems useful to preserve this comment in t
agl 2011/10/17 17:37:24 Done.
75 static const char kNpnProtosFullV1[] = "\x08http/1.1\x06spdy/1";
76 // No spdy specified.
77 static const char kNpnProtosHttpOnly[] = "\x08http/1.1\x07http1.1";
78
79 std::vector<std::string> spdy_options; 67 std::vector<std::string> spdy_options;
80 base::SplitString(mode, ',', &spdy_options); 68 base::SplitString(mode, ',', &spdy_options);
81 69
82 bool use_alt_protocols = true; 70 bool use_alt_protocols = true;
83 71
84 for (std::vector<std::string>::iterator it = spdy_options.begin(); 72 for (std::vector<std::string>::iterator it = spdy_options.begin();
85 it != spdy_options.end(); ++it) { 73 it != spdy_options.end(); ++it) {
86 const std::string& element = *it; 74 const std::string& element = *it;
87 std::vector<std::string> name_value; 75 std::vector<std::string> name_value;
88 base::SplitString(element, '=', &name_value); 76 base::SplitString(element, '=', &name_value);
89 const std::string& option = name_value[0]; 77 const std::string& option = name_value[0];
90 const std::string value = name_value.size() > 1 ? name_value[1] : ""; 78 const std::string value = name_value.size() > 1 ? name_value[1] : "";
91 79
92 if (option == kOff) { 80 if (option == kOff) {
93 HttpStreamFactory::set_spdy_enabled(false); 81 HttpStreamFactory::set_spdy_enabled(false);
94 } else if (option == kDisableSSL) { 82 } else if (option == kDisableSSL) {
95 SpdySession::SetSSLMode(false); // Disable SSL 83 SpdySession::SetSSLMode(false); // Disable SSL
96 HttpStreamFactory::set_force_spdy_over_ssl(false); 84 HttpStreamFactory::set_force_spdy_over_ssl(false);
97 HttpStreamFactory::set_force_spdy_always(true); 85 HttpStreamFactory::set_force_spdy_always(true);
98 } else if (option == kSSL) { 86 } else if (option == kSSL) {
99 HttpStreamFactory::set_force_spdy_over_ssl(true); 87 HttpStreamFactory::set_force_spdy_over_ssl(true);
100 HttpStreamFactory::set_force_spdy_always(true); 88 HttpStreamFactory::set_force_spdy_always(true);
101 } else if (option == kExclude) { 89 } else if (option == kExclude) {
102 HttpStreamFactory::add_forced_spdy_exclusion(value); 90 HttpStreamFactory::add_forced_spdy_exclusion(value);
103 } else if (option == kDisableCompression) { 91 } else if (option == kDisableCompression) {
104 spdy::SpdyFramer::set_enable_compression_default(false); 92 spdy::SpdyFramer::set_enable_compression_default(false);
105 } else if (option == kEnableNPN) { 93 } else if (option == kEnableNPN) {
106 HttpStreamFactory::set_use_alternate_protocols(use_alt_protocols); 94 HttpStreamFactory::set_use_alternate_protocols(use_alt_protocols);
107 HttpStreamFactory::set_next_protos(kNpnProtosFull); 95 std::vector<std::string> next_protos;
96 next_protos.push_back("http/1.1");
97 next_protos.push_back("spdy/2");
98 HttpStreamFactory::set_next_protos(next_protos);
108 } else if (option == kEnableNpnHttpOnly) { 99 } else if (option == kEnableNpnHttpOnly) {
109 // Avoid alternate protocol in this case. Otherwise, browser will try SSL 100 // Avoid alternate protocol in this case. Otherwise, browser will try SSL
110 // and then fallback to http. This introduces extra load. 101 // and then fallback to http. This introduces extra load.
111 HttpStreamFactory::set_use_alternate_protocols(false); 102 HttpStreamFactory::set_use_alternate_protocols(false);
112 HttpStreamFactory::set_next_protos(kNpnProtosHttpOnly); 103 std::vector<std::string> next_protos;
104 next_protos.push_back("http/1.1");
105 next_protos.push_back("http1.1");
106 HttpStreamFactory::set_next_protos(next_protos);
113 } else if (option == kEnableVersionOne) { 107 } else if (option == kEnableVersionOne) {
114 spdy::SpdyFramer::set_protocol_version(1); 108 spdy::SpdyFramer::set_protocol_version(1);
115 HttpStreamFactory::set_next_protos(kNpnProtosFullV1); 109 std::vector<std::string> next_protos;
110 next_protos.push_back("http/1.1");
111 next_protos.push_back("spdy/1");
112 HttpStreamFactory::set_next_protos(next_protos);
116 } else if (option == kDisableAltProtocols) { 113 } else if (option == kDisableAltProtocols) {
117 use_alt_protocols = false; 114 use_alt_protocols = false;
118 HttpStreamFactory::set_use_alternate_protocols(false); 115 HttpStreamFactory::set_use_alternate_protocols(false);
119 } else if (option == kEnableFlowControl) { 116 } else if (option == kEnableFlowControl) {
120 SpdySession::set_flow_control(true); 117 SpdySession::set_flow_control(true);
121 } else if (option == kForceAltProtocols) { 118 } else if (option == kForceAltProtocols) {
122 HttpAlternateProtocols::PortProtocolPair pair; 119 HttpAlternateProtocols::PortProtocolPair pair;
123 pair.port = 443; 120 pair.port = 443;
124 pair.protocol = HttpAlternateProtocols::NPN_SPDY_2; 121 pair.protocol = HttpAlternateProtocols::NPN_SPDY_2;
125 HttpAlternateProtocols::ForceAlternateProtocol(pair); 122 HttpAlternateProtocols::ForceAlternateProtocol(pair);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 154
158 if (session_) 155 if (session_)
159 session_->CloseIdleConnections(); 156 session_->CloseIdleConnections();
160 } 157 }
161 158
162 void HttpNetworkLayer::OnResume() { 159 void HttpNetworkLayer::OnResume() {
163 suspended_ = false; 160 suspended_ = false;
164 } 161 }
165 162
166 } // namespace net 163 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698