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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 = |
71 AlternateProtocolFromString(port_protocol_vector[1]); | 71 AlternateProtocolFromString(port_protocol_vector[1]); |
Ryan Hamilton
2014/11/05 17:05:20
Can this fit on one line?
Can you confirm what wi
Bence
2014/11/06 00:26:00
Sorry, git cl format is broken on my machine.
| |
72 | |
72 if (IsAlternateProtocolValid(protocol) && | 73 if (IsAlternateProtocolValid(protocol) && |
73 !session.IsProtocolEnabled(protocol)) { | 74 !session.IsProtocolEnabled(protocol)) { |
74 protocol = ALTERNATE_PROTOCOL_BROKEN; | |
75 } | |
76 | |
77 if (protocol == ALTERNATE_PROTOCOL_BROKEN) { | |
78 DVLOG(1) << kAlternateProtocolHeader | 75 DVLOG(1) << kAlternateProtocolHeader |
79 << " header has unrecognized protocol: " | 76 << " header has unrecognized protocol: " |
80 << port_protocol_vector[1]; | 77 << port_protocol_vector[1]; |
81 return; | 78 return; |
82 } | 79 } |
83 } | 80 } |
84 | 81 |
85 if (protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) | 82 if (protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
86 return; | 83 return; |
87 | 84 |
88 HostPortPair host_port(http_host_port_pair); | 85 HostPortPair host_port(http_host_port_pair); |
89 const HostMappingRules* mapping_rules = GetHostMappingRules(); | 86 const HostMappingRules* mapping_rules = GetHostMappingRules(); |
90 if (mapping_rules) | 87 if (mapping_rules) |
91 mapping_rules->RewriteHost(&host_port); | 88 mapping_rules->RewriteHost(&host_port); |
92 | 89 |
93 if (http_server_properties->HasAlternateProtocol(host_port)) { | 90 if (http_server_properties->HasAlternateProtocol(host_port)) { |
94 const AlternateProtocolInfo existing_alternate = | 91 const AlternateProtocolInfo existing_alternate = |
95 http_server_properties->GetAlternateProtocol(host_port); | 92 http_server_properties->GetAlternateProtocol(host_port); |
96 // If we think the alternate protocol is broken, don't change it. | 93 // If we think the alternate protocol is broken, don't change it. |
97 if (existing_alternate.protocol == ALTERNATE_PROTOCOL_BROKEN) | 94 if (existing_alternate.is_broken) { |
98 return; | 95 return; |
96 } | |
Ryan Hamilton
2014/11/05 17:05:20
net/ style prohibits {}s on one-line ifs. Whee!
Bence
2014/11/06 00:26:00
Lovely.
Done.
| |
99 } | 97 } |
100 | 98 |
101 http_server_properties->SetAlternateProtocol(host_port, port, protocol, | 99 http_server_properties->SetAlternateProtocol(host_port, port, protocol, |
102 probability); | 100 probability); |
103 } | 101 } |
104 | 102 |
105 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, | 103 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, |
106 HostPortPair* endpoint) { | 104 HostPortPair* endpoint) { |
107 const HostMappingRules* mapping_rules = GetHostMappingRules(); | 105 const HostMappingRules* mapping_rules = GetHostMappingRules(); |
108 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { | 106 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { |
109 url::Replacements<char> replacements; | 107 url::Replacements<char> replacements; |
110 const std::string port_str = base::IntToString(endpoint->port()); | 108 const std::string port_str = base::IntToString(endpoint->port()); |
111 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size())); | 109 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size())); |
112 replacements.SetHost(endpoint->host().c_str(), | 110 replacements.SetHost(endpoint->host().c_str(), |
113 url::Component(0, endpoint->host().size())); | 111 url::Component(0, endpoint->host().size())); |
114 return url.ReplaceComponents(replacements); | 112 return url.ReplaceComponents(replacements); |
115 } | 113 } |
116 return url; | 114 return url; |
117 } | 115 } |
118 | 116 |
119 HttpStreamFactory::HttpStreamFactory() {} | 117 HttpStreamFactory::HttpStreamFactory() {} |
120 | 118 |
121 } // namespace net | 119 } // namespace net |
OLD | NEW |