Chromium Code Reviews| 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::supported_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 = NPN_SPDY_1; i < NUM_ALTERNATE_PROTOCOLS; ++i) | |
|
Ryan Hamilton
2012/03/02 16:46:53
Start at 0 just to be simple.
ramant (doing other things)
2012/03/02 18:40:41
Done.
| |
| 61 supported_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 // We skip NPN_SPDY_1 here, because we've rolled the protocol version to 2. |
| 85 for (int i = NPN_SPDY_2; i < NUM_ALTERNATE_PROTOCOLS; ++i) { | 88 for (int i = NPN_SPDY_2; i < NUM_ALTERNATE_PROTOCOLS; ++i) { |
|
Ryan Hamilton
2012/03/02 16:46:53
Please start at 0. If we want to avoid SPDY_1, ei
ramant (doing other things)
2012/03/02 18:40:41
Done.
| |
| 86 if (port_protocol_vector[1] == kAlternateProtocolStrings[i]) | 89 if (supported_protocols_[i] && |
| 90 port_protocol_vector[1] == kAlternateProtocolStrings[i]) { | |
| 87 protocol = static_cast<AlternateProtocol>(i); | 91 protocol = static_cast<AlternateProtocol>(i); |
| 92 } | |
| 88 } | 93 } |
| 89 | 94 |
| 90 if (protocol == ALTERNATE_PROTOCOL_BROKEN) { | 95 if (protocol == ALTERNATE_PROTOCOL_BROKEN) { |
| 91 // Currently, we only recognize the npn-spdy protocol. | 96 // Currently, we only recognize the npn-spdy protocol. |
| 92 DLOG(WARNING) << kAlternateProtocolHeader | 97 DLOG(WARNING) << kAlternateProtocolHeader |
| 93 << " header has unrecognized protocol: " | 98 << " header has unrecognized protocol: " |
| 94 << port_protocol_vector[1]; | 99 << port_protocol_vector[1]; |
| 95 return; | 100 return; |
| 96 } | 101 } |
| 97 | 102 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 return false; | 143 return false; |
| 139 | 144 |
| 140 std::list<HostPortPair>::const_iterator it; | 145 std::list<HostPortPair>::const_iterator it; |
| 141 for (it = exclusions->begin(); it != exclusions->end(); ++it) | 146 for (it = exclusions->begin(); it != exclusions->end(); ++it) |
| 142 if (it->Equals(endpoint)) | 147 if (it->Equals(endpoint)) |
| 143 return true; | 148 return true; |
| 144 return false; | 149 return false; |
| 145 } | 150 } |
| 146 | 151 |
| 147 // static | 152 // static |
| 153 void HttpStreamFactory::SetNextProtos(const std::vector<std::string>& value) { | |
| 154 if (!next_protos_) | |
| 155 next_protos_ = new std::vector<std::string>; | |
| 156 | |
| 157 *next_protos_ = value; | |
| 158 | |
| 159 for (uint32 i = NPN_SPDY_1; i < NUM_ALTERNATE_PROTOCOLS; ++i) | |
| 160 supported_protocols_[i] = false; | |
| 161 | |
| 162 for (uint32 i = 0; i < value.size(); ++i) { | |
|
Ryan Hamilton
2012/03/02 16:46:53
Let's not hard-code the strings again, please. Ho
ramant (doing other things)
2012/03/02 18:40:41
As we had discussed, added a TODO and issue 116575
| |
| 163 if (value[i] == "spdy/1") { | |
| 164 supported_protocols_[NPN_SPDY_1] = true; | |
| 165 } else if (value[i] == "spdy/2") { | |
| 166 supported_protocols_[NPN_SPDY_2] = true; | |
| 167 } else if (value[i] == "spdy/2.1") { | |
| 168 supported_protocols_[NPN_SPDY_21] = true; | |
| 169 } | |
| 170 } | |
| 171 } | |
| 172 | |
| 173 // static | |
| 148 void HttpStreamFactory::SetHostMappingRules(const std::string& rules) { | 174 void HttpStreamFactory::SetHostMappingRules(const std::string& rules) { |
| 149 HostMappingRules* host_mapping_rules = new HostMappingRules; | 175 HostMappingRules* host_mapping_rules = new HostMappingRules; |
| 150 host_mapping_rules->SetRulesFromString(rules); | 176 host_mapping_rules->SetRulesFromString(rules); |
| 151 delete host_mapping_rules_; | 177 delete host_mapping_rules_; |
| 152 host_mapping_rules_ = host_mapping_rules; | 178 host_mapping_rules_ = host_mapping_rules; |
| 153 } | 179 } |
| 154 | 180 |
| 155 HttpStreamFactory::HttpStreamFactory() {} | 181 HttpStreamFactory::HttpStreamFactory() {} |
| 156 | 182 |
| 157 // static | 183 // static |
| 158 const HostMappingRules& HttpStreamFactory::host_mapping_rules() { | 184 const HostMappingRules& HttpStreamFactory::host_mapping_rules() { |
| 159 if (!host_mapping_rules_) | 185 if (!host_mapping_rules_) |
| 160 host_mapping_rules_ = new HostMappingRules; | 186 host_mapping_rules_ = new HostMappingRules; |
| 161 return *host_mapping_rules_; | 187 return *host_mapping_rules_; |
| 162 } | 188 } |
| 163 | 189 |
| 164 } // namespace net | 190 } // namespace net |
| OLD | NEW |