| OLD | NEW |
| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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 |
| 36 // static | 37 // static |
| 37 bool HttpStreamFactory::IsProtocolEnabled(AlternateProtocol protocol) { | 38 bool HttpStreamFactory::IsProtocolEnabled(AlternateProtocol protocol) { |
| 38 DCHECK(IsAlternateProtocolValid(protocol)); | 39 DCHECK(IsAlternateProtocolValid(protocol)); |
| 39 return enabled_protocols_[ | 40 return enabled_protocols_[protocol - |
| 40 protocol - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION]; | 41 ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION]; |
| 41 } | 42 } |
| 42 | 43 |
| 43 // static | 44 // static |
| 44 void HttpStreamFactory::SetProtocolEnabled(AlternateProtocol protocol) { | 45 void HttpStreamFactory::SetProtocolEnabled(AlternateProtocol protocol) { |
| 45 DCHECK(IsAlternateProtocolValid(protocol)); | 46 DCHECK(IsAlternateProtocolValid(protocol)); |
| 46 enabled_protocols_[ | 47 enabled_protocols_[protocol - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION] = |
| 47 protocol - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION] = true; | 48 true; |
| 48 } | 49 } |
| 49 | 50 |
| 50 // static | 51 // static |
| 51 void HttpStreamFactory::ResetEnabledProtocols() { | 52 void HttpStreamFactory::ResetEnabledProtocols() { |
| 52 for (int i = ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION; | 53 for (int i = ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION; |
| 53 i <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION; ++i) { | 54 i <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION; |
| 55 ++i) { |
| 54 enabled_protocols_[i - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION] = false; | 56 enabled_protocols_[i - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION] = false; |
| 55 } | 57 } |
| 56 } | 58 } |
| 57 | 59 |
| 58 // static | 60 // static |
| 59 void HttpStreamFactory::ResetStaticSettingsToInit() { | 61 void HttpStreamFactory::ResetStaticSettingsToInit() { |
| 60 // WARNING: These must match the initializers above. | 62 // WARNING: These must match the initializers above. |
| 61 delete next_protos_; | 63 delete next_protos_; |
| 62 delete forced_spdy_exclusions_; | 64 delete forced_spdy_exclusions_; |
| 63 next_protos_ = NULL; | 65 next_protos_ = NULL; |
| 64 spdy_enabled_ = true; | 66 spdy_enabled_ = true; |
| 65 use_alternate_protocols_ = false; | 67 use_alternate_protocols_ = false; |
| 66 force_spdy_over_ssl_ = true; | 68 force_spdy_over_ssl_ = true; |
| 67 force_spdy_always_ = false; | 69 force_spdy_always_ = false; |
| 68 forced_spdy_exclusions_ = NULL; | 70 forced_spdy_exclusions_ = NULL; |
| 69 ResetEnabledProtocols(); | 71 ResetEnabledProtocols(); |
| 70 } | 72 } |
| 71 | 73 |
| 72 void HttpStreamFactory::ProcessAlternateProtocol( | 74 void HttpStreamFactory::ProcessAlternateProtocol( |
| 73 const base::WeakPtr<HttpServerProperties>& http_server_properties, | 75 const base::WeakPtr<HttpServerProperties>& http_server_properties, |
| 74 const std::string& alternate_protocol_str, | 76 const std::string& alternate_protocol_str, |
| 75 const HostPortPair& http_host_port_pair) { | 77 const HostPortPair& http_host_port_pair) { |
| 76 std::vector<std::string> port_protocol_vector; | 78 std::vector<std::string> port_protocol_vector; |
| 77 base::SplitString(alternate_protocol_str, ':', &port_protocol_vector); | 79 base::SplitString(alternate_protocol_str, ':', &port_protocol_vector); |
| 78 if (port_protocol_vector.size() != 2) { | 80 if (port_protocol_vector.size() != 2) { |
| 79 DVLOG(1) << kAlternateProtocolHeader | 81 DVLOG(1) << kAlternateProtocolHeader |
| 80 << " header has too many tokens: " | 82 << " header has too many tokens: " << alternate_protocol_str; |
| 81 << alternate_protocol_str; | |
| 82 return; | 83 return; |
| 83 } | 84 } |
| 84 | 85 |
| 85 int port; | 86 int port; |
| 86 if (!base::StringToInt(port_protocol_vector[0], &port) || | 87 if (!base::StringToInt(port_protocol_vector[0], &port) || port <= 0 || |
| 87 port <= 0 || port >= 1 << 16) { | 88 port >= 1 << 16) { |
| 88 DVLOG(1) << kAlternateProtocolHeader | 89 DVLOG(1) << kAlternateProtocolHeader |
| 89 << " header has unrecognizable port: " | 90 << " header has unrecognizable port: " << port_protocol_vector[0]; |
| 90 << port_protocol_vector[0]; | |
| 91 return; | 91 return; |
| 92 } | 92 } |
| 93 | 93 |
| 94 AlternateProtocol protocol = | 94 AlternateProtocol protocol = |
| 95 AlternateProtocolFromString(port_protocol_vector[1]); | 95 AlternateProtocolFromString(port_protocol_vector[1]); |
| 96 if (IsAlternateProtocolValid(protocol) && !IsProtocolEnabled(protocol)) { | 96 if (IsAlternateProtocolValid(protocol) && !IsProtocolEnabled(protocol)) { |
| 97 protocol = ALTERNATE_PROTOCOL_BROKEN; | 97 protocol = ALTERNATE_PROTOCOL_BROKEN; |
| 98 } | 98 } |
| 99 | 99 |
| 100 if (protocol == ALTERNATE_PROTOCOL_BROKEN) { | 100 if (protocol == ALTERNATE_PROTOCOL_BROKEN) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 AlternateProtocol alternate = AlternateProtocolFromNextProto(proto); | 235 AlternateProtocol alternate = AlternateProtocolFromNextProto(proto); |
| 236 if (!IsAlternateProtocolValid(alternate)) { | 236 if (!IsAlternateProtocolValid(alternate)) { |
| 237 NOTREACHED() << "Invalid next proto: " << proto; | 237 NOTREACHED() << "Invalid next proto: " << proto; |
| 238 continue; | 238 continue; |
| 239 } | 239 } |
| 240 SetProtocolEnabled(alternate); | 240 SetProtocolEnabled(alternate); |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 } | 243 } |
| 244 | 244 |
| 245 HttpStreamFactory::HttpStreamFactory() {} | 245 HttpStreamFactory::HttpStreamFactory() { |
| 246 } |
| 246 | 247 |
| 247 } // namespace net | 248 } // namespace net |
| OLD | NEW |