| 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/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 "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "net/base/host_mapping_rules.h" | 11 #include "net/base/host_mapping_rules.h" |
| 12 #include "net/base/host_port_pair.h" | 12 #include "net/base/host_port_pair.h" |
| 13 #include "net/http/http_server_properties.h" | |
| 14 | 13 |
| 15 namespace net { | 14 namespace net { |
| 16 | 15 |
| 17 // 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 |
| 18 // with |ResetStaticSettingsToInit|. This is critical for unit test isolation. | 17 // with |ResetStaticSettingsToInit|. This is critical for unit test isolation. |
| 19 | 18 |
| 20 // static | 19 // static |
| 21 const HostMappingRules* HttpStreamFactory::host_mapping_rules_ = NULL; | 20 const HostMappingRules* HttpStreamFactory::host_mapping_rules_ = NULL; |
| 22 // static | 21 // static |
| 23 std::vector<std::string>* HttpStreamFactory::next_protos_ = NULL; | 22 std::vector<std::string>* HttpStreamFactory::next_protos_ = NULL; |
| 24 // static | 23 // static |
| 24 bool HttpStreamFactory::enabled_protocols_[NUM_ALTERNATE_PROTOCOLS]; |
| 25 // static |
| 25 bool HttpStreamFactory::spdy_enabled_ = true; | 26 bool HttpStreamFactory::spdy_enabled_ = true; |
| 26 // static | 27 // static |
| 27 bool HttpStreamFactory::use_alternate_protocols_ = false; | 28 bool HttpStreamFactory::use_alternate_protocols_ = false; |
| 28 // static | 29 // static |
| 29 bool HttpStreamFactory::force_spdy_over_ssl_ = true; | 30 bool HttpStreamFactory::force_spdy_over_ssl_ = true; |
| 30 // static | 31 // static |
| 31 bool HttpStreamFactory::force_spdy_always_ = false; | 32 bool HttpStreamFactory::force_spdy_always_ = false; |
| 32 // static | 33 // static |
| 33 std::list<HostPortPair>* HttpStreamFactory::forced_spdy_exclusions_ = NULL; | 34 std::list<HostPortPair>* HttpStreamFactory::forced_spdy_exclusions_ = NULL; |
| 34 // static | 35 // static |
| (...skipping 14 matching lines...) Expand all Loading... |
| 49 delete next_protos_; | 50 delete next_protos_; |
| 50 delete forced_spdy_exclusions_; | 51 delete forced_spdy_exclusions_; |
| 51 host_mapping_rules_ = NULL; | 52 host_mapping_rules_ = NULL; |
| 52 next_protos_ = NULL; | 53 next_protos_ = NULL; |
| 53 spdy_enabled_ = true; | 54 spdy_enabled_ = true; |
| 54 use_alternate_protocols_ = false; | 55 use_alternate_protocols_ = false; |
| 55 force_spdy_over_ssl_ = true; | 56 force_spdy_over_ssl_ = true; |
| 56 force_spdy_always_ = false; | 57 force_spdy_always_ = false; |
| 57 forced_spdy_exclusions_ = NULL; | 58 forced_spdy_exclusions_ = NULL; |
| 58 ignore_certificate_errors_ = false; | 59 ignore_certificate_errors_ = false; |
| 60 for (int i = 0; i < NUM_ALTERNATE_PROTOCOLS; ++i) |
| 61 enabled_protocols_[i] = false; |
| 59 } | 62 } |
| 60 | 63 |
| 61 void HttpStreamFactory::ProcessAlternateProtocol( | 64 void HttpStreamFactory::ProcessAlternateProtocol( |
| 62 HttpServerProperties* http_server_properties, | 65 HttpServerProperties* http_server_properties, |
| 63 const std::string& alternate_protocol_str, | 66 const std::string& alternate_protocol_str, |
| 64 const HostPortPair& http_host_port_pair) { | 67 const HostPortPair& http_host_port_pair) { |
| 65 std::vector<std::string> port_protocol_vector; | 68 std::vector<std::string> port_protocol_vector; |
| 66 base::SplitString(alternate_protocol_str, ':', &port_protocol_vector); | 69 base::SplitString(alternate_protocol_str, ':', &port_protocol_vector); |
| 67 if (port_protocol_vector.size() != 2) { | 70 if (port_protocol_vector.size() != 2) { |
| 68 DLOG(WARNING) << kAlternateProtocolHeader | 71 DLOG(WARNING) << kAlternateProtocolHeader |
| 69 << " header has too many tokens: " | 72 << " header has too many tokens: " |
| 70 << alternate_protocol_str; | 73 << alternate_protocol_str; |
| 71 return; | 74 return; |
| 72 } | 75 } |
| 73 | 76 |
| 74 int port; | 77 int port; |
| 75 if (!base::StringToInt(port_protocol_vector[0], &port) || | 78 if (!base::StringToInt(port_protocol_vector[0], &port) || |
| 76 port <= 0 || port >= 1 << 16) { | 79 port <= 0 || port >= 1 << 16) { |
| 77 DLOG(WARNING) << kAlternateProtocolHeader | 80 DLOG(WARNING) << kAlternateProtocolHeader |
| 78 << " header has unrecognizable port: " | 81 << " header has unrecognizable port: " |
| 79 << port_protocol_vector[0]; | 82 << port_protocol_vector[0]; |
| 80 return; | 83 return; |
| 81 } | 84 } |
| 82 | 85 |
| 83 AlternateProtocol protocol = ALTERNATE_PROTOCOL_BROKEN; | 86 AlternateProtocol protocol = ALTERNATE_PROTOCOL_BROKEN; |
| 84 // We skip NPN_SPDY_1 here, because we've rolled the protocol version to 2. | 87 for (int i = 0; i < NUM_ALTERNATE_PROTOCOLS; ++i) { |
| 85 for (int i = NPN_SPDY_2; i < NUM_ALTERNATE_PROTOCOLS; ++i) { | 88 if (enabled_protocols_[i] && |
| 86 if (port_protocol_vector[1] == kAlternateProtocolStrings[i]) | 89 port_protocol_vector[1] == kAlternateProtocolStrings[i]) { |
| 87 protocol = static_cast<AlternateProtocol>(i); | 90 protocol = static_cast<AlternateProtocol>(i); |
| 91 } |
| 88 } | 92 } |
| 89 | 93 |
| 90 if (protocol == ALTERNATE_PROTOCOL_BROKEN) { | 94 if (protocol == ALTERNATE_PROTOCOL_BROKEN) { |
| 91 // Currently, we only recognize the npn-spdy protocol. | 95 // Currently, we only recognize the npn-spdy protocol. |
| 92 DLOG(WARNING) << kAlternateProtocolHeader | 96 DLOG(WARNING) << kAlternateProtocolHeader |
| 93 << " header has unrecognized protocol: " | 97 << " header has unrecognized protocol: " |
| 94 << port_protocol_vector[1]; | 98 << port_protocol_vector[1]; |
| 95 return; | 99 return; |
| 96 } | 100 } |
| 97 | 101 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 return false; | 142 return false; |
| 139 | 143 |
| 140 std::list<HostPortPair>::const_iterator it; | 144 std::list<HostPortPair>::const_iterator it; |
| 141 for (it = exclusions->begin(); it != exclusions->end(); ++it) | 145 for (it = exclusions->begin(); it != exclusions->end(); ++it) |
| 142 if (it->Equals(endpoint)) | 146 if (it->Equals(endpoint)) |
| 143 return true; | 147 return true; |
| 144 return false; | 148 return false; |
| 145 } | 149 } |
| 146 | 150 |
| 147 // static | 151 // static |
| 152 void HttpStreamFactory::SetNextProtos(const std::vector<std::string>& value) { |
| 153 if (!next_protos_) |
| 154 next_protos_ = new std::vector<std::string>; |
| 155 |
| 156 *next_protos_ = value; |
| 157 |
| 158 for (uint32 i = 0; i < NUM_ALTERNATE_PROTOCOLS; ++i) |
| 159 enabled_protocols_[i] = false; |
| 160 |
| 161 // TODO(rtenneti): bug 116575 - consider using same strings/enums for SPDY |
| 162 // versions in next_protos and kAlternateProtocolStrings. |
| 163 for (uint32 i = 0; i < value.size(); ++i) { |
| 164 if (value[i] == "spdy/1") { |
| 165 enabled_protocols_[NPN_SPDY_1] = true; |
| 166 } else if (value[i] == "spdy/2") { |
| 167 enabled_protocols_[NPN_SPDY_2] = true; |
| 168 } else if (value[i] == "spdy/2.1") { |
| 169 enabled_protocols_[NPN_SPDY_21] = true; |
| 170 } |
| 171 } |
| 172 enabled_protocols_[NPN_SPDY_1] = false; |
| 173 } |
| 174 |
| 175 // static |
| 148 void HttpStreamFactory::SetHostMappingRules(const std::string& rules) { | 176 void HttpStreamFactory::SetHostMappingRules(const std::string& rules) { |
| 149 HostMappingRules* host_mapping_rules = new HostMappingRules; | 177 HostMappingRules* host_mapping_rules = new HostMappingRules; |
| 150 host_mapping_rules->SetRulesFromString(rules); | 178 host_mapping_rules->SetRulesFromString(rules); |
| 151 delete host_mapping_rules_; | 179 delete host_mapping_rules_; |
| 152 host_mapping_rules_ = host_mapping_rules; | 180 host_mapping_rules_ = host_mapping_rules; |
| 153 } | 181 } |
| 154 | 182 |
| 155 HttpStreamFactory::HttpStreamFactory() {} | 183 HttpStreamFactory::HttpStreamFactory() {} |
| 156 | 184 |
| 157 // static | 185 // static |
| 158 const HostMappingRules& HttpStreamFactory::host_mapping_rules() { | 186 const HostMappingRules& HttpStreamFactory::host_mapping_rules() { |
| 159 if (!host_mapping_rules_) | 187 if (!host_mapping_rules_) |
| 160 host_mapping_rules_ = new HostMappingRules; | 188 host_mapping_rules_ = new HostMappingRules; |
| 161 return *host_mapping_rules_; | 189 return *host_mapping_rules_; |
| 162 } | 190 } |
| 163 | 191 |
| 164 } // namespace net | 192 } // namespace net |
| OLD | NEW |