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 | 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 const HostMappingRules* HttpStreamFactory::host_mapping_rules_ = NULL; | |
21 // static | |
22 std::vector<std::string>* HttpStreamFactory::next_protos_ = NULL; | 20 std::vector<std::string>* HttpStreamFactory::next_protos_ = NULL; |
23 // static | 21 // static |
24 bool HttpStreamFactory::enabled_protocols_[NUM_ALTERNATE_PROTOCOLS]; | 22 bool HttpStreamFactory::enabled_protocols_[NUM_ALTERNATE_PROTOCOLS]; |
25 // static | 23 // static |
26 bool HttpStreamFactory::spdy_enabled_ = true; | 24 bool HttpStreamFactory::spdy_enabled_ = true; |
27 // static | 25 // static |
28 bool HttpStreamFactory::use_alternate_protocols_ = false; | 26 bool HttpStreamFactory::use_alternate_protocols_ = false; |
29 // static | 27 // static |
30 bool HttpStreamFactory::force_spdy_over_ssl_ = true; | 28 bool HttpStreamFactory::force_spdy_over_ssl_ = true; |
31 // static | 29 // static |
32 bool HttpStreamFactory::force_spdy_always_ = false; | 30 bool HttpStreamFactory::force_spdy_always_ = false; |
33 // static | 31 // static |
34 std::list<HostPortPair>* HttpStreamFactory::forced_spdy_exclusions_ = NULL; | 32 std::list<HostPortPair>* HttpStreamFactory::forced_spdy_exclusions_ = NULL; |
35 // static | |
36 bool HttpStreamFactory::ignore_certificate_errors_ = false; | |
37 // static | |
38 bool HttpStreamFactory::http_pipelining_enabled_ = false; | |
39 // static | |
40 uint16 HttpStreamFactory::testing_fixed_http_port_ = 0; | |
41 // static | |
42 uint16 HttpStreamFactory::testing_fixed_https_port_ = 0; | |
43 | 33 |
44 HttpStreamFactory::~HttpStreamFactory() {} | 34 HttpStreamFactory::~HttpStreamFactory() {} |
45 | 35 |
46 // static | 36 // static |
47 void HttpStreamFactory::ResetStaticSettingsToInit() { | 37 void HttpStreamFactory::ResetStaticSettingsToInit() { |
48 // WARNING: These must match the initializers above. | 38 // WARNING: These must match the initializers above. |
49 delete host_mapping_rules_; | |
50 delete next_protos_; | 39 delete next_protos_; |
51 delete forced_spdy_exclusions_; | 40 delete forced_spdy_exclusions_; |
52 host_mapping_rules_ = NULL; | |
53 next_protos_ = NULL; | 41 next_protos_ = NULL; |
54 spdy_enabled_ = true; | 42 spdy_enabled_ = true; |
55 use_alternate_protocols_ = false; | 43 use_alternate_protocols_ = false; |
56 force_spdy_over_ssl_ = true; | 44 force_spdy_over_ssl_ = true; |
57 force_spdy_always_ = false; | 45 force_spdy_always_ = false; |
58 forced_spdy_exclusions_ = NULL; | 46 forced_spdy_exclusions_ = NULL; |
59 ignore_certificate_errors_ = false; | |
60 for (int i = 0; i < NUM_ALTERNATE_PROTOCOLS; ++i) | 47 for (int i = 0; i < NUM_ALTERNATE_PROTOCOLS; ++i) |
61 enabled_protocols_[i] = false; | 48 enabled_protocols_[i] = false; |
62 } | 49 } |
63 | 50 |
64 void HttpStreamFactory::ProcessAlternateProtocol( | 51 void HttpStreamFactory::ProcessAlternateProtocol( |
65 HttpServerProperties* http_server_properties, | 52 HttpServerProperties* http_server_properties, |
66 const std::string& alternate_protocol_str, | 53 const std::string& alternate_protocol_str, |
67 const HostPortPair& http_host_port_pair) { | 54 const HostPortPair& http_host_port_pair) { |
68 std::vector<std::string> port_protocol_vector; | 55 std::vector<std::string> port_protocol_vector; |
69 base::SplitString(alternate_protocol_str, ':', &port_protocol_vector); | 56 base::SplitString(alternate_protocol_str, ':', &port_protocol_vector); |
(...skipping 23 matching lines...) Expand all Loading... |
93 | 80 |
94 if (protocol == ALTERNATE_PROTOCOL_BROKEN) { | 81 if (protocol == ALTERNATE_PROTOCOL_BROKEN) { |
95 // Currently, we only recognize the npn-spdy protocol. | 82 // Currently, we only recognize the npn-spdy protocol. |
96 DLOG(WARNING) << kAlternateProtocolHeader | 83 DLOG(WARNING) << kAlternateProtocolHeader |
97 << " header has unrecognized protocol: " | 84 << " header has unrecognized protocol: " |
98 << port_protocol_vector[1]; | 85 << port_protocol_vector[1]; |
99 return; | 86 return; |
100 } | 87 } |
101 | 88 |
102 HostPortPair host_port(http_host_port_pair); | 89 HostPortPair host_port(http_host_port_pair); |
103 host_mapping_rules().RewriteHost(&host_port); | 90 const HostMappingRules* mapping_rules = GetHostMappingRules(); |
| 91 if (mapping_rules) |
| 92 mapping_rules->RewriteHost(&host_port); |
104 | 93 |
105 if (http_server_properties->HasAlternateProtocol(host_port)) { | 94 if (http_server_properties->HasAlternateProtocol(host_port)) { |
106 const PortAlternateProtocolPair existing_alternate = | 95 const PortAlternateProtocolPair existing_alternate = |
107 http_server_properties->GetAlternateProtocol(host_port); | 96 http_server_properties->GetAlternateProtocol(host_port); |
108 // If we think the alternate protocol is broken, don't change it. | 97 // If we think the alternate protocol is broken, don't change it. |
109 if (existing_alternate.protocol == ALTERNATE_PROTOCOL_BROKEN) | 98 if (existing_alternate.protocol == ALTERNATE_PROTOCOL_BROKEN) |
110 return; | 99 return; |
111 } | 100 } |
112 | 101 |
113 http_server_properties->SetAlternateProtocol(host_port, port, protocol); | 102 http_server_properties->SetAlternateProtocol(host_port, port, protocol); |
114 } | 103 } |
115 | 104 |
116 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, | 105 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, |
117 HostPortPair* endpoint) { | 106 HostPortPair* endpoint) { |
118 if (host_mapping_rules().RewriteHost(endpoint)) { | 107 const HostMappingRules* mapping_rules = GetHostMappingRules(); |
| 108 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { |
119 url_canon::Replacements<char> replacements; | 109 url_canon::Replacements<char> replacements; |
120 const std::string port_str = base::IntToString(endpoint->port()); | 110 const std::string port_str = base::IntToString(endpoint->port()); |
121 replacements.SetPort(port_str.c_str(), | 111 replacements.SetPort(port_str.c_str(), |
122 url_parse::Component(0, port_str.size())); | 112 url_parse::Component(0, port_str.size())); |
123 replacements.SetHost(endpoint->host().c_str(), | 113 replacements.SetHost(endpoint->host().c_str(), |
124 url_parse::Component(0, endpoint->host().size())); | 114 url_parse::Component(0, endpoint->host().size())); |
125 return url.ReplaceComponents(replacements); | 115 return url.ReplaceComponents(replacements); |
126 } | 116 } |
127 return url; | 117 return url; |
128 } | 118 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 enabled_protocols_[NPN_SPDY_1] = true; | 185 enabled_protocols_[NPN_SPDY_1] = true; |
196 } else if (value[i] == "spdy/2") { | 186 } else if (value[i] == "spdy/2") { |
197 enabled_protocols_[NPN_SPDY_2] = true; | 187 enabled_protocols_[NPN_SPDY_2] = true; |
198 } else if (value[i] == "spdy/3") { | 188 } else if (value[i] == "spdy/3") { |
199 enabled_protocols_[NPN_SPDY_3] = true; | 189 enabled_protocols_[NPN_SPDY_3] = true; |
200 } | 190 } |
201 } | 191 } |
202 enabled_protocols_[NPN_SPDY_1] = false; | 192 enabled_protocols_[NPN_SPDY_1] = false; |
203 } | 193 } |
204 | 194 |
205 // static | |
206 void HttpStreamFactory::SetHostMappingRules(const std::string& rules) { | |
207 HostMappingRules* host_mapping_rules = new HostMappingRules; | |
208 host_mapping_rules->SetRulesFromString(rules); | |
209 delete host_mapping_rules_; | |
210 host_mapping_rules_ = host_mapping_rules; | |
211 } | |
212 | |
213 HttpStreamFactory::HttpStreamFactory() {} | 195 HttpStreamFactory::HttpStreamFactory() {} |
214 | 196 |
215 // static | |
216 const HostMappingRules& HttpStreamFactory::host_mapping_rules() { | |
217 if (!host_mapping_rules_) | |
218 host_mapping_rules_ = new HostMappingRules; | |
219 return *host_mapping_rules_; | |
220 } | |
221 | |
222 } // namespace net | 197 } // namespace net |
OLD | NEW |