| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 || port >= 1 << 16) { |
| 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 = | 70 protocol = AlternateProtocolFromString(port_protocol_vector[1]); |
| 71 AlternateProtocolFromString(port_protocol_vector[1]); | 71 |
| 72 if (IsAlternateProtocolValid(protocol) && | 72 if (IsAlternateProtocolValid(protocol) && |
| 73 !session.IsProtocolEnabled(protocol)) { | 73 !session.IsProtocolEnabled(protocol)) { |
| 74 protocol = ALTERNATE_PROTOCOL_BROKEN; | |
| 75 } | |
| 76 | |
| 77 if (protocol == ALTERNATE_PROTOCOL_BROKEN) { | |
| 78 DVLOG(1) << kAlternateProtocolHeader | 74 DVLOG(1) << kAlternateProtocolHeader |
| 79 << " header has unrecognized protocol: " | 75 << " header has unrecognized protocol: " |
| 80 << port_protocol_vector[1]; | 76 << port_protocol_vector[1]; |
| 81 return; | 77 return; |
| 82 } | 78 } |
| 83 } | 79 } |
| 84 | 80 |
| 85 if (protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) | 81 if (protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
| 86 return; | 82 return; |
| 87 | 83 |
| 88 HostPortPair host_port(http_host_port_pair); | 84 HostPortPair host_port(http_host_port_pair); |
| 89 const HostMappingRules* mapping_rules = GetHostMappingRules(); | 85 const HostMappingRules* mapping_rules = GetHostMappingRules(); |
| 90 if (mapping_rules) | 86 if (mapping_rules) |
| 91 mapping_rules->RewriteHost(&host_port); | 87 mapping_rules->RewriteHost(&host_port); |
| 92 | 88 |
| 93 if (http_server_properties->HasAlternateProtocol(host_port)) { | 89 if (http_server_properties->HasAlternateProtocol(host_port)) { |
| 94 const AlternateProtocolInfo existing_alternate = | 90 const AlternateProtocolInfo existing_alternate = |
| 95 http_server_properties->GetAlternateProtocol(host_port); | 91 http_server_properties->GetAlternateProtocol(host_port); |
| 96 // 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. |
| 97 if (existing_alternate.protocol == ALTERNATE_PROTOCOL_BROKEN) | 93 if (existing_alternate.is_broken) |
| 98 return; | 94 return; |
| 99 } | 95 } |
| 100 | 96 |
| 101 http_server_properties->SetAlternateProtocol(host_port, port, protocol, | 97 http_server_properties->SetAlternateProtocol(host_port, port, protocol, |
| 102 probability); | 98 probability); |
| 103 } | 99 } |
| 104 | 100 |
| 105 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, | 101 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, |
| 106 HostPortPair* endpoint) { | 102 HostPortPair* endpoint) { |
| 107 const HostMappingRules* mapping_rules = GetHostMappingRules(); | 103 const HostMappingRules* mapping_rules = GetHostMappingRules(); |
| 108 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { | 104 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { |
| 109 url::Replacements<char> replacements; | 105 url::Replacements<char> replacements; |
| 110 const std::string port_str = base::IntToString(endpoint->port()); | 106 const std::string port_str = base::IntToString(endpoint->port()); |
| 111 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())); |
| 112 replacements.SetHost(endpoint->host().c_str(), | 108 replacements.SetHost(endpoint->host().c_str(), |
| 113 url::Component(0, endpoint->host().size())); | 109 url::Component(0, endpoint->host().size())); |
| 114 return url.ReplaceComponents(replacements); | 110 return url.ReplaceComponents(replacements); |
| 115 } | 111 } |
| 116 return url; | 112 return url; |
| 117 } | 113 } |
| 118 | 114 |
| 119 HttpStreamFactory::HttpStreamFactory() {} | 115 HttpStreamFactory::HttpStreamFactory() {} |
| 120 | 116 |
| 121 } // namespace net | 117 } // namespace net |
| OLD | NEW |