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

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

Issue 25956002: [SPDY] Remove references to obsolete SPDY versions SPDY/1 and SPDY/2.1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test Created 7 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
« no previous file with comments | « net/http/http_stream_factory.h ('k') | net/http/http_stream_factory_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_stream_factory.h" 5 #include "net/http/http_stream_factory.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "net/base/host_mapping_rules.h" 10 #include "net/base/host_mapping_rules.h"
11 #include "net/base/host_port_pair.h" 11 #include "net/base/host_port_pair.h"
12 #include "url/gurl.h" 12 #include "url/gurl.h"
13 13
14 namespace net { 14 namespace net {
15 15
16 // WARNING: If you modify or add any static flags, you must keep them in sync 16 // WARNING: If you modify or add any static flags, you must keep them in sync
17 // with |ResetStaticSettingsToInit|. This is critical for unit test isolation. 17 // with |ResetStaticSettingsToInit|. This is critical for unit test isolation.
18 18
19 // static 19 // static
20 std::vector<std::string>* HttpStreamFactory::next_protos_ = NULL; 20 std::vector<std::string>* HttpStreamFactory::next_protos_ = NULL;
21 // static 21 // static
22 bool HttpStreamFactory::enabled_protocols_[NUM_ALTERNATE_PROTOCOLS]; 22 bool HttpStreamFactory::enabled_protocols_[NUM_VALID_ALTERNATE_PROTOCOLS];
23 // static 23 // static
24 bool HttpStreamFactory::spdy_enabled_ = true; 24 bool HttpStreamFactory::spdy_enabled_ = true;
25 // static 25 // static
26 bool HttpStreamFactory::use_alternate_protocols_ = false; 26 bool HttpStreamFactory::use_alternate_protocols_ = false;
27 // static 27 // static
28 bool HttpStreamFactory::force_spdy_over_ssl_ = true; 28 bool HttpStreamFactory::force_spdy_over_ssl_ = true;
29 // static 29 // static
30 bool HttpStreamFactory::force_spdy_always_ = false; 30 bool HttpStreamFactory::force_spdy_always_ = false;
31 // static 31 // static
32 std::list<HostPortPair>* HttpStreamFactory::forced_spdy_exclusions_ = NULL; 32 std::list<HostPortPair>* HttpStreamFactory::forced_spdy_exclusions_ = NULL;
33 33
34 HttpStreamFactory::~HttpStreamFactory() {} 34 HttpStreamFactory::~HttpStreamFactory() {}
35 35
36 // static 36 // static
37 bool HttpStreamFactory::IsProtocolEnabled(AlternateProtocol protocol) {
38 DCHECK(IsAlternateProtocolValid(protocol));
39 return enabled_protocols_[
40 protocol - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION];
41 }
42
43 // static
44 void HttpStreamFactory::SetProtocolEnabled(AlternateProtocol protocol) {
45 DCHECK(IsAlternateProtocolValid(protocol));
46 enabled_protocols_[
47 protocol - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION] = true;
48 }
49
50 // static
51 void HttpStreamFactory::ResetEnabledProtocols() {
52 for (int i = ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION;
53 i <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION; ++i) {
54 enabled_protocols_[i - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION] = false;
55 }
56 }
57
58 // static
37 void HttpStreamFactory::ResetStaticSettingsToInit() { 59 void HttpStreamFactory::ResetStaticSettingsToInit() {
38 // WARNING: These must match the initializers above. 60 // WARNING: These must match the initializers above.
39 delete next_protos_; 61 delete next_protos_;
40 delete forced_spdy_exclusions_; 62 delete forced_spdy_exclusions_;
41 next_protos_ = NULL; 63 next_protos_ = NULL;
42 spdy_enabled_ = true; 64 spdy_enabled_ = true;
43 use_alternate_protocols_ = false; 65 use_alternate_protocols_ = false;
44 force_spdy_over_ssl_ = true; 66 force_spdy_over_ssl_ = true;
45 force_spdy_always_ = false; 67 force_spdy_always_ = false;
46 forced_spdy_exclusions_ = NULL; 68 forced_spdy_exclusions_ = NULL;
47 for (int i = 0; i < NUM_ALTERNATE_PROTOCOLS; ++i) 69 ResetEnabledProtocols();
48 enabled_protocols_[i] = false;
49 } 70 }
50 71
51 void HttpStreamFactory::ProcessAlternateProtocol( 72 void HttpStreamFactory::ProcessAlternateProtocol(
52 const base::WeakPtr<HttpServerProperties>& http_server_properties, 73 const base::WeakPtr<HttpServerProperties>& http_server_properties,
53 const std::string& alternate_protocol_str, 74 const std::string& alternate_protocol_str,
54 const HostPortPair& http_host_port_pair) { 75 const HostPortPair& http_host_port_pair) {
55 std::vector<std::string> port_protocol_vector; 76 std::vector<std::string> port_protocol_vector;
56 base::SplitString(alternate_protocol_str, ':', &port_protocol_vector); 77 base::SplitString(alternate_protocol_str, ':', &port_protocol_vector);
57 if (port_protocol_vector.size() != 2) { 78 if (port_protocol_vector.size() != 2) {
58 DLOG(WARNING) << kAlternateProtocolHeader 79 DLOG(WARNING) << kAlternateProtocolHeader
59 << " header has too many tokens: " 80 << " header has too many tokens: "
60 << alternate_protocol_str; 81 << alternate_protocol_str;
61 return; 82 return;
62 } 83 }
63 84
64 int port; 85 int port;
65 if (!base::StringToInt(port_protocol_vector[0], &port) || 86 if (!base::StringToInt(port_protocol_vector[0], &port) ||
66 port <= 0 || port >= 1 << 16) { 87 port <= 0 || port >= 1 << 16) {
67 DLOG(WARNING) << kAlternateProtocolHeader 88 DLOG(WARNING) << kAlternateProtocolHeader
68 << " header has unrecognizable port: " 89 << " header has unrecognizable port: "
69 << port_protocol_vector[0]; 90 << port_protocol_vector[0];
70 return; 91 return;
71 } 92 }
72 93
73 AlternateProtocol protocol = 94 AlternateProtocol protocol =
74 AlternateProtocolFromString(port_protocol_vector[1]); 95 AlternateProtocolFromString(port_protocol_vector[1]);
75 if (protocol < NUM_ALTERNATE_PROTOCOLS && !enabled_protocols_[protocol]) 96 if (IsAlternateProtocolValid(protocol) && !IsProtocolEnabled(protocol)) {
76 protocol = ALTERNATE_PROTOCOL_BROKEN; 97 protocol = ALTERNATE_PROTOCOL_BROKEN;
98 }
77 99
78 if (protocol == ALTERNATE_PROTOCOL_BROKEN) { 100 if (protocol == ALTERNATE_PROTOCOL_BROKEN) {
79 // Currently, we only recognize the npn-spdy protocol.
80 DLOG(WARNING) << kAlternateProtocolHeader 101 DLOG(WARNING) << kAlternateProtocolHeader
81 << " header has unrecognized protocol: " 102 << " header has unrecognized protocol: "
82 << port_protocol_vector[1]; 103 << port_protocol_vector[1];
83 return; 104 return;
84 } 105 }
85 106
86 HostPortPair host_port(http_host_port_pair); 107 HostPortPair host_port(http_host_port_pair);
87 const HostMappingRules* mapping_rules = GetHostMappingRules(); 108 const HostMappingRules* mapping_rules = GetHostMappingRules();
88 if (mapping_rules) 109 if (mapping_rules)
89 mapping_rules->RewriteHost(&host_port); 110 mapping_rules->RewriteHost(&host_port);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 SetNextProtos(next_protos); 226 SetNextProtos(next_protos);
206 } 227 }
207 228
208 // static 229 // static
209 void HttpStreamFactory::SetNextProtos(const std::vector<NextProto>& value) { 230 void HttpStreamFactory::SetNextProtos(const std::vector<NextProto>& value) {
210 if (!next_protos_) 231 if (!next_protos_)
211 next_protos_ = new std::vector<std::string>; 232 next_protos_ = new std::vector<std::string>;
212 233
213 next_protos_->clear(); 234 next_protos_->clear();
214 235
215 for (uint32 i = 0; i < NUM_ALTERNATE_PROTOCOLS; ++i) 236 ResetEnabledProtocols();
216 enabled_protocols_[i] = false;
217 237
218 // TODO(rtenneti): bug 116575 - consider combining the NextProto and 238 // TODO(rtenneti): bug 116575 - consider combining the NextProto and
219 // AlternateProtocol. 239 // AlternateProtocol.
220 for (uint32 i = 0; i < value.size(); ++i) { 240 for (uint32 i = 0; i < value.size(); ++i) {
221 NextProto proto = value[i]; 241 NextProto proto = value[i];
222 // Add the protocol to the TLS next protocol list, except for QUIC 242 // Add the protocol to the TLS next protocol list, except for QUIC
223 // since it uses UDP. 243 // since it uses UDP.
224 if (proto != kProtoQUIC1SPDY3) { 244 if (proto != kProtoQUIC1SPDY3) {
225 next_protos_->push_back(SSLClientSocket::NextProtoToString(proto)); 245 next_protos_->push_back(SSLClientSocket::NextProtoToString(proto));
226 } 246 }
227 247
228 // Enable the corresponding alternate protocol, except for HTTP 248 // Enable the corresponding alternate protocol, except for HTTP
229 // which has not corresponding alternative. 249 // which has not corresponding alternative.
230 if (proto != kProtoHTTP11) { 250 if (proto != kProtoHTTP11) {
231 AlternateProtocol alternate = AlternateProtocolFromNextProto(proto); 251 AlternateProtocol alternate = AlternateProtocolFromNextProto(proto);
232 if (alternate == UNINITIALIZED_ALTERNATE_PROTOCOL) { 252 if (!IsAlternateProtocolValid(alternate)) {
233 NOTREACHED() << "Invalid next proto: " << proto; 253 NOTREACHED() << "Invalid next proto: " << proto;
234 continue; 254 continue;
235 } 255 }
236 enabled_protocols_[alternate] = true; 256 SetProtocolEnabled(alternate);
237 } 257 }
238 } 258 }
239 } 259 }
240 260
241 HttpStreamFactory::HttpStreamFactory() {} 261 HttpStreamFactory::HttpStreamFactory() {}
242 262
243 } // namespace net 263 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory.h ('k') | net/http/http_stream_factory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698