| 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 "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 if (!match_found) { | 72 if (!match_found) { |
| 73 continue; | 73 continue; |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 AlternativeService alternative_service(protocol, | 76 AlternativeService alternative_service(protocol, |
| 77 alternative_service_entry.host, | 77 alternative_service_entry.host, |
| 78 alternative_service_entry.port); | 78 alternative_service_entry.port); |
| 79 base::Time expiration = | 79 base::Time expiration = |
| 80 base::Time::Now() + | 80 base::Time::Now() + |
| 81 base::TimeDelta::FromSeconds(alternative_service_entry.max_age); | 81 base::TimeDelta::FromSeconds(alternative_service_entry.max_age); |
| 82 AlternativeServiceInfo alternative_service_info( | 82 AlternativeServiceInfo alternative_service_info(alternative_service, |
| 83 alternative_service, alternative_service_entry.probability, expiration); | 83 expiration); |
| 84 alternative_service_info_vector.push_back(alternative_service_info); | 84 alternative_service_info_vector.push_back(alternative_service_info); |
| 85 } | 85 } |
| 86 | 86 |
| 87 http_server_properties->SetAlternativeServices( | 87 http_server_properties->SetAlternativeServices( |
| 88 RewriteHost(http_host_port_pair), alternative_service_info_vector); | 88 RewriteHost(http_host_port_pair), alternative_service_info_vector); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void HttpStreamFactory::ProcessAlternateProtocol( | 91 void HttpStreamFactory::ProcessAlternateProtocol( |
| 92 const base::WeakPtr<HttpServerProperties>& http_server_properties, | 92 const base::WeakPtr<HttpServerProperties>& http_server_properties, |
| 93 const std::vector<std::string>& alternate_protocol_values, | 93 const std::vector<std::string>& alternate_protocol_values, |
| 94 const HostPortPair& http_host_port_pair, | 94 const HostPortPair& http_host_port_pair, |
| 95 const HttpNetworkSession& session) { | 95 const HttpNetworkSession& session) { |
| 96 AlternateProtocol protocol = UNINITIALIZED_ALTERNATE_PROTOCOL; | 96 AlternateProtocol protocol = UNINITIALIZED_ALTERNATE_PROTOCOL; |
| 97 int port = 0; | 97 int port = 0; |
| 98 double probability = 1; | |
| 99 bool is_valid = true; | 98 bool is_valid = true; |
| 100 for (size_t i = 0; i < alternate_protocol_values.size(); ++i) { | 99 for (size_t i = 0; i < alternate_protocol_values.size(); ++i) { |
| 101 base::StringPiece alternate_protocol_str = alternate_protocol_values[i]; | 100 base::StringPiece alternate_protocol_str = alternate_protocol_values[i]; |
| 102 if (base::StartsWith(alternate_protocol_str, "p=", | |
| 103 base::CompareCase::SENSITIVE)) { | |
| 104 if (!base::StringToDouble(alternate_protocol_str.substr(2).as_string(), | |
| 105 &probability) || | |
| 106 probability < 0 || probability > 1) { | |
| 107 DVLOG(1) << kAlternateProtocolHeader | |
| 108 << " header has unrecognizable probability: " | |
| 109 << alternate_protocol_values[i]; | |
| 110 is_valid = false; | |
| 111 break; | |
| 112 } | |
| 113 continue; | |
| 114 } | |
| 115 | |
| 116 std::vector<base::StringPiece> port_protocol_vector = | 101 std::vector<base::StringPiece> port_protocol_vector = |
| 117 base::SplitStringPiece(alternate_protocol_str, ":", | 102 base::SplitStringPiece(alternate_protocol_str, ":", |
| 118 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 103 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 119 if (port_protocol_vector.size() != 2) { | 104 if (port_protocol_vector.size() != 2) { |
| 120 DVLOG(1) << kAlternateProtocolHeader | 105 DVLOG(1) << kAlternateProtocolHeader |
| 121 << " header has too many tokens: " | 106 << " header has too many tokens: " |
| 122 << alternate_protocol_str; | 107 << alternate_protocol_str; |
| 123 is_valid = false; | 108 is_valid = false; |
| 124 break; | 109 break; |
| 125 } | 110 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 146 } | 131 } |
| 147 | 132 |
| 148 if (!is_valid || protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { | 133 if (!is_valid || protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { |
| 149 http_server_properties->ClearAlternativeServices(http_host_port_pair); | 134 http_server_properties->ClearAlternativeServices(http_host_port_pair); |
| 150 return; | 135 return; |
| 151 } | 136 } |
| 152 | 137 |
| 153 http_server_properties->SetAlternativeService( | 138 http_server_properties->SetAlternativeService( |
| 154 RewriteHost(http_host_port_pair), | 139 RewriteHost(http_host_port_pair), |
| 155 AlternativeService(protocol, "", static_cast<uint16_t>(port)), | 140 AlternativeService(protocol, "", static_cast<uint16_t>(port)), |
| 156 probability, base::Time::Now() + base::TimeDelta::FromDays(30)); | 141 base::Time::Now() + base::TimeDelta::FromDays(30)); |
| 157 } | 142 } |
| 158 | 143 |
| 159 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, | 144 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, |
| 160 HostPortPair* endpoint) { | 145 HostPortPair* endpoint) { |
| 161 const HostMappingRules* mapping_rules = GetHostMappingRules(); | 146 const HostMappingRules* mapping_rules = GetHostMappingRules(); |
| 162 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { | 147 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { |
| 163 url::Replacements<char> replacements; | 148 url::Replacements<char> replacements; |
| 164 const std::string port_str = base::UintToString(endpoint->port()); | 149 const std::string port_str = base::UintToString(endpoint->port()); |
| 165 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size())); | 150 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size())); |
| 166 replacements.SetHost(endpoint->host().c_str(), | 151 replacements.SetHost(endpoint->host().c_str(), |
| 167 url::Component(0, endpoint->host().size())); | 152 url::Component(0, endpoint->host().size())); |
| 168 return url.ReplaceComponents(replacements); | 153 return url.ReplaceComponents(replacements); |
| 169 } | 154 } |
| 170 return url; | 155 return url; |
| 171 } | 156 } |
| 172 | 157 |
| 173 HttpStreamFactory::HttpStreamFactory() {} | 158 HttpStreamFactory::HttpStreamFactory() {} |
| 174 | 159 |
| 175 HostPortPair HttpStreamFactory::RewriteHost(HostPortPair host_port_pair) { | 160 HostPortPair HttpStreamFactory::RewriteHost(HostPortPair host_port_pair) { |
| 176 const HostMappingRules* mapping_rules = GetHostMappingRules(); | 161 const HostMappingRules* mapping_rules = GetHostMappingRules(); |
| 177 if (mapping_rules) | 162 if (mapping_rules) |
| 178 mapping_rules->RewriteHost(&host_port_pair); | 163 mapping_rules->RewriteHost(&host_port_pair); |
| 179 return host_port_pair; | 164 return host_port_pair; |
| 180 } | 165 } |
| 181 | 166 |
| 182 } // namespace net | 167 } // namespace net |
| OLD | NEW |