Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: net/http/http_stream_factory.cc

Issue 1824903002: Change the AlternativeServiceMap with SchemeOriginPair key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unittests Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 17 matching lines...) Expand all
28 HttpStreamFactory::~HttpStreamFactory() {} 28 HttpStreamFactory::~HttpStreamFactory() {}
29 29
30 // static 30 // static
31 void HttpStreamFactory::ResetStaticSettingsToInit() { 31 void HttpStreamFactory::ResetStaticSettingsToInit() {
32 spdy_enabled_ = true; 32 spdy_enabled_ = true;
33 } 33 }
34 34
35 void HttpStreamFactory::ProcessAlternativeService( 35 void HttpStreamFactory::ProcessAlternativeService(
36 const base::WeakPtr<HttpServerProperties>& http_server_properties, 36 const base::WeakPtr<HttpServerProperties>& http_server_properties,
37 base::StringPiece alternative_service_str, 37 base::StringPiece alternative_service_str,
38 const HostPortPair& http_host_port_pair, 38 const SchemeOriginPair& scheme_origin_pair,
39 const HttpNetworkSession& session) { 39 const HttpNetworkSession& session) {
40 SpdyAltSvcWireFormat::AlternativeServiceVector alternative_service_vector; 40 SpdyAltSvcWireFormat::AlternativeServiceVector alternative_service_vector;
41 if (!SpdyAltSvcWireFormat::ParseHeaderFieldValue( 41 if (!SpdyAltSvcWireFormat::ParseHeaderFieldValue(
42 alternative_service_str, &alternative_service_vector)) { 42 alternative_service_str, &alternative_service_vector)) {
43 return; 43 return;
44 } 44 }
45 45
46 // Convert SpdyAltSvcWireFormat::AlternativeService entries 46 // Convert SpdyAltSvcWireFormat::AlternativeService entries
47 // to net::AlternativeServiceInfo. 47 // to net::AlternativeServiceInfo.
48 AlternativeServiceInfoVector alternative_service_info_vector; 48 AlternativeServiceInfoVector alternative_service_info_vector;
(...skipping 29 matching lines...) Expand all
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(
83 alternative_service, alternative_service_entry.probability, 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 SchemeOriginPair(scheme_origin_pair.scheme(),
89 RewriteHost(scheme_origin_pair.host_port_pair())),
90 alternative_service_info_vector);
89 } 91 }
90 92
91 void HttpStreamFactory::ProcessAlternateProtocol( 93 void HttpStreamFactory::ProcessAlternateProtocol(
92 const base::WeakPtr<HttpServerProperties>& http_server_properties, 94 const base::WeakPtr<HttpServerProperties>& http_server_properties,
93 const std::vector<std::string>& alternate_protocol_values, 95 const std::vector<std::string>& alternate_protocol_values,
94 const HostPortPair& http_host_port_pair, 96 const SchemeOriginPair& scheme_origin_pair,
95 const HttpNetworkSession& session) { 97 const HttpNetworkSession& session) {
96 AlternateProtocol protocol = UNINITIALIZED_ALTERNATE_PROTOCOL; 98 AlternateProtocol protocol = UNINITIALIZED_ALTERNATE_PROTOCOL;
97 int port = 0; 99 int port = 0;
98 double probability = 1; 100 double probability = 1;
99 bool is_valid = true; 101 bool is_valid = true;
100 for (size_t i = 0; i < alternate_protocol_values.size(); ++i) { 102 for (size_t i = 0; i < alternate_protocol_values.size(); ++i) {
101 base::StringPiece alternate_protocol_str = alternate_protocol_values[i]; 103 base::StringPiece alternate_protocol_str = alternate_protocol_values[i];
102 if (base::StartsWith(alternate_protocol_str, "p=", 104 if (base::StartsWith(alternate_protocol_str, "p=",
103 base::CompareCase::SENSITIVE)) { 105 base::CompareCase::SENSITIVE)) {
104 if (!base::StringToDouble(alternate_protocol_str.substr(2).as_string(), 106 if (!base::StringToDouble(alternate_protocol_str.substr(2).as_string(),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 !session.IsProtocolEnabled(protocol)) { 141 !session.IsProtocolEnabled(protocol)) {
140 DVLOG(1) << kAlternateProtocolHeader 142 DVLOG(1) << kAlternateProtocolHeader
141 << " header has unrecognized protocol: " 143 << " header has unrecognized protocol: "
142 << port_protocol_vector[1]; 144 << port_protocol_vector[1];
143 is_valid = false; 145 is_valid = false;
144 break; 146 break;
145 } 147 }
146 } 148 }
147 149
148 if (!is_valid || protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { 150 if (!is_valid || protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) {
149 http_server_properties->ClearAlternativeServices(http_host_port_pair); 151 http_server_properties->ClearAlternativeServices(scheme_origin_pair);
150 return; 152 return;
151 } 153 }
152 154
153 http_server_properties->SetAlternativeService( 155 http_server_properties->SetAlternativeService(
154 RewriteHost(http_host_port_pair), 156 SchemeOriginPair(scheme_origin_pair.scheme(),
157 RewriteHost(scheme_origin_pair.host_port_pair())),
155 AlternativeService(protocol, "", static_cast<uint16_t>(port)), 158 AlternativeService(protocol, "", static_cast<uint16_t>(port)),
156 probability, base::Time::Now() + base::TimeDelta::FromDays(30)); 159 probability, base::Time::Now() + base::TimeDelta::FromDays(30));
157 } 160 }
158 161
159 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, 162 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url,
160 HostPortPair* endpoint) { 163 HostPortPair* endpoint) {
161 const HostMappingRules* mapping_rules = GetHostMappingRules(); 164 const HostMappingRules* mapping_rules = GetHostMappingRules();
162 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { 165 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) {
163 url::Replacements<char> replacements; 166 url::Replacements<char> replacements;
164 const std::string port_str = base::UintToString(endpoint->port()); 167 const std::string port_str = base::UintToString(endpoint->port());
165 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size())); 168 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size()));
166 replacements.SetHost(endpoint->host().c_str(), 169 replacements.SetHost(endpoint->host().c_str(),
167 url::Component(0, endpoint->host().size())); 170 url::Component(0, endpoint->host().size()));
168 return url.ReplaceComponents(replacements); 171 return url.ReplaceComponents(replacements);
169 } 172 }
170 return url; 173 return url;
171 } 174 }
172 175
173 HttpStreamFactory::HttpStreamFactory() {} 176 HttpStreamFactory::HttpStreamFactory() {}
174 177
175 HostPortPair HttpStreamFactory::RewriteHost(HostPortPair host_port_pair) { 178 HostPortPair HttpStreamFactory::RewriteHost(HostPortPair host_port_pair) {
176 const HostMappingRules* mapping_rules = GetHostMappingRules(); 179 const HostMappingRules* mapping_rules = GetHostMappingRules();
177 if (mapping_rules) 180 if (mapping_rules)
178 mapping_rules->RewriteHost(&host_port_pair); 181 mapping_rules->RewriteHost(&host_port_pair);
179 return host_port_pair; 182 return host_port_pair;
180 } 183 }
181 184
182 } // namespace net 185 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698