| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 std::vector<std::string> port_protocol_vector; | 53 std::vector<std::string> port_protocol_vector; |
| 54 base::SplitString(alternate_protocol_str, ':', &port_protocol_vector); | 54 base::SplitString(alternate_protocol_str, ':', &port_protocol_vector); |
| 55 if (port_protocol_vector.size() != 2) { | 55 if (port_protocol_vector.size() != 2) { |
| 56 DVLOG(1) << kAlternateProtocolHeader | 56 DVLOG(1) << kAlternateProtocolHeader |
| 57 << " header has too many tokens: " | 57 << " header has too many tokens: " |
| 58 << alternate_protocol_str; | 58 << alternate_protocol_str; |
| 59 return; | 59 return; |
| 60 } | 60 } |
| 61 | 61 |
| 62 if (!base::StringToInt(port_protocol_vector[0], &port) || | 62 if (!base::StringToInt(port_protocol_vector[0], &port) || |
| 63 port <= 0 || port >= 1 << 16) { | 63 port == 0 || !IsPortValid(port)) { |
| 64 DVLOG(1) << kAlternateProtocolHeader | 64 DVLOG(1) << kAlternateProtocolHeader |
| 65 << " header has unrecognizable port: " | 65 << " header has unrecognizable port: " |
| 66 << port_protocol_vector[0]; | 66 << port_protocol_vector[0]; |
| 67 return; | 67 return; |
| 68 } | 68 } |
| 69 | 69 |
| 70 protocol = AlternateProtocolFromString(port_protocol_vector[1]); | 70 protocol = AlternateProtocolFromString(port_protocol_vector[1]); |
| 71 | 71 |
| 72 if (IsAlternateProtocolValid(protocol) && | 72 if (IsAlternateProtocolValid(protocol) && |
| 73 !session.IsProtocolEnabled(protocol)) { | 73 !session.IsProtocolEnabled(protocol)) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 87 mapping_rules->RewriteHost(&host_port); | 87 mapping_rules->RewriteHost(&host_port); |
| 88 | 88 |
| 89 if (http_server_properties->HasAlternateProtocol(host_port)) { | 89 if (http_server_properties->HasAlternateProtocol(host_port)) { |
| 90 const AlternateProtocolInfo existing_alternate = | 90 const AlternateProtocolInfo existing_alternate = |
| 91 http_server_properties->GetAlternateProtocol(host_port); | 91 http_server_properties->GetAlternateProtocol(host_port); |
| 92 // If we think the alternate protocol is broken, don't change it. | 92 // If we think the alternate protocol is broken, don't change it. |
| 93 if (existing_alternate.is_broken) | 93 if (existing_alternate.is_broken) |
| 94 return; | 94 return; |
| 95 } | 95 } |
| 96 | 96 |
| 97 http_server_properties->SetAlternateProtocol(host_port, port, protocol, | 97 http_server_properties->SetAlternateProtocol( |
| 98 probability); | 98 host_port, static_cast<uint16>(port), protocol, probability); |
| 99 } | 99 } |
| 100 | 100 |
| 101 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, | 101 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, |
| 102 HostPortPair* endpoint) { | 102 HostPortPair* endpoint) { |
| 103 const HostMappingRules* mapping_rules = GetHostMappingRules(); | 103 const HostMappingRules* mapping_rules = GetHostMappingRules(); |
| 104 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { | 104 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { |
| 105 url::Replacements<char> replacements; | 105 url::Replacements<char> replacements; |
| 106 const std::string port_str = base::IntToString(endpoint->port()); | 106 const std::string port_str = base::IntToString(endpoint->port()); |
| 107 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size())); | 107 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size())); |
| 108 replacements.SetHost(endpoint->host().c_str(), | 108 replacements.SetHost(endpoint->host().c_str(), |
| 109 url::Component(0, endpoint->host().size())); | 109 url::Component(0, endpoint->host().size())); |
| 110 return url.ReplaceComponents(replacements); | 110 return url.ReplaceComponents(replacements); |
| 111 } | 111 } |
| 112 return url; | 112 return url; |
| 113 } | 113 } |
| 114 | 114 |
| 115 HttpStreamFactory::HttpStreamFactory() {} | 115 HttpStreamFactory::HttpStreamFactory() {} |
| 116 | 116 |
| 117 } // namespace net | 117 } // namespace net |
| OLD | NEW |