| 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(alternative_service, | 82 AlternativeServiceInfo alternative_service_info( |
| 83 expiration); | 83 alternative_service, alternative_service_entry.probability, 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; |
| 98 bool is_valid = true; | 99 bool is_valid = true; |
| 99 for (size_t i = 0; i < alternate_protocol_values.size(); ++i) { | 100 for (size_t i = 0; i < alternate_protocol_values.size(); ++i) { |
| 100 base::StringPiece alternate_protocol_str = alternate_protocol_values[i]; | 101 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 |
| 101 std::vector<base::StringPiece> port_protocol_vector = | 116 std::vector<base::StringPiece> port_protocol_vector = |
| 102 base::SplitStringPiece(alternate_protocol_str, ":", | 117 base::SplitStringPiece(alternate_protocol_str, ":", |
| 103 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 118 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 104 if (port_protocol_vector.size() != 2) { | 119 if (port_protocol_vector.size() != 2) { |
| 105 DVLOG(1) << kAlternateProtocolHeader | 120 DVLOG(1) << kAlternateProtocolHeader |
| 106 << " header has too many tokens: " | 121 << " header has too many tokens: " |
| 107 << alternate_protocol_str; | 122 << alternate_protocol_str; |
| 108 is_valid = false; | 123 is_valid = false; |
| 109 break; | 124 break; |
| 110 } | 125 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 131 } | 146 } |
| 132 | 147 |
| 133 if (!is_valid || protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { | 148 if (!is_valid || protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { |
| 134 http_server_properties->ClearAlternativeServices(http_host_port_pair); | 149 http_server_properties->ClearAlternativeServices(http_host_port_pair); |
| 135 return; | 150 return; |
| 136 } | 151 } |
| 137 | 152 |
| 138 http_server_properties->SetAlternativeService( | 153 http_server_properties->SetAlternativeService( |
| 139 RewriteHost(http_host_port_pair), | 154 RewriteHost(http_host_port_pair), |
| 140 AlternativeService(protocol, "", static_cast<uint16_t>(port)), | 155 AlternativeService(protocol, "", static_cast<uint16_t>(port)), |
| 141 base::Time::Now() + base::TimeDelta::FromDays(30)); | 156 probability, base::Time::Now() + base::TimeDelta::FromDays(30)); |
| 142 } | 157 } |
| 143 | 158 |
| 144 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, | 159 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, |
| 145 HostPortPair* endpoint) { | 160 HostPortPair* endpoint) { |
| 146 const HostMappingRules* mapping_rules = GetHostMappingRules(); | 161 const HostMappingRules* mapping_rules = GetHostMappingRules(); |
| 147 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { | 162 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { |
| 148 url::Replacements<char> replacements; | 163 url::Replacements<char> replacements; |
| 149 const std::string port_str = base::UintToString(endpoint->port()); | 164 const std::string port_str = base::UintToString(endpoint->port()); |
| 150 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size())); | 165 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size())); |
| 151 replacements.SetHost(endpoint->host().c_str(), | 166 replacements.SetHost(endpoint->host().c_str(), |
| 152 url::Component(0, endpoint->host().size())); | 167 url::Component(0, endpoint->host().size())); |
| 153 return url.ReplaceComponents(replacements); | 168 return url.ReplaceComponents(replacements); |
| 154 } | 169 } |
| 155 return url; | 170 return url; |
| 156 } | 171 } |
| 157 | 172 |
| 158 HttpStreamFactory::HttpStreamFactory() {} | 173 HttpStreamFactory::HttpStreamFactory() {} |
| 159 | 174 |
| 160 HostPortPair HttpStreamFactory::RewriteHost(HostPortPair host_port_pair) { | 175 HostPortPair HttpStreamFactory::RewriteHost(HostPortPair host_port_pair) { |
| 161 const HostMappingRules* mapping_rules = GetHostMappingRules(); | 176 const HostMappingRules* mapping_rules = GetHostMappingRules(); |
| 162 if (mapping_rules) | 177 if (mapping_rules) |
| 163 mapping_rules->RewriteHost(&host_port_pair); | 178 mapping_rules->RewriteHost(&host_port_pair); |
| 164 return host_port_pair; | 179 return host_port_pair; |
| 165 } | 180 } |
| 166 | 181 |
| 167 } // namespace net | 182 } // namespace net |
| OLD | NEW |