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

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

Issue 1817583002: Process Alternative Service headers in net::BidirectionalStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@toggle2
Patch Set: Address comments and rebased 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
« no previous file with comments | « net/http/http_stream_factory.h ('k') | net/spdy/spdy_test_util_common.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "net/base/host_mapping_rules.h" 12 #include "net/base/host_mapping_rules.h"
13 #include "net/base/host_port_pair.h" 13 #include "net/base/host_port_pair.h"
14 #include "net/base/port_util.h" 14 #include "net/base/port_util.h"
15 #include "net/http/http_network_session.h" 15 #include "net/http/http_network_session.h"
16 #include "net/http/http_response_headers.h"
16 #include "net/quic/quic_protocol.h" 17 #include "net/quic/quic_protocol.h"
17 #include "net/spdy/spdy_alt_svc_wire_format.h" 18 #include "net/spdy/spdy_alt_svc_wire_format.h"
18 #include "url/gurl.h" 19 #include "url/gurl.h"
19 20
20 namespace net { 21 namespace net {
21 22
22 // WARNING: If you modify or add any static flags, you must keep them in sync 23 // WARNING: If you modify or add any static flags, you must keep them in sync
23 // with |ResetStaticSettingsToInit|. This is critical for unit test isolation. 24 // with |ResetStaticSettingsToInit|. This is critical for unit test isolation.
24 25
25 // static 26 // static
26 bool HttpStreamFactory::spdy_enabled_ = true; 27 bool HttpStreamFactory::spdy_enabled_ = true;
27 28
28 HttpStreamFactory::~HttpStreamFactory() {} 29 HttpStreamFactory::~HttpStreamFactory() {}
29 30
30 // static 31 // static
31 void HttpStreamFactory::ResetStaticSettingsToInit() { 32 void HttpStreamFactory::ResetStaticSettingsToInit() {
32 spdy_enabled_ = true; 33 spdy_enabled_ = true;
33 } 34 }
34 35
36 void HttpStreamFactory::ProcessAlternativeServices(
37 HttpNetworkSession* session,
38 const HttpResponseHeaders* headers,
39 const HostPortPair& http_host_port_pair) {
40 if (session->params().parse_alternative_services) {
41 if (headers->HasHeader(kAlternativeServiceHeader)) {
42 std::string alternative_service_str;
43 headers->GetNormalizedHeader(kAlternativeServiceHeader,
44 &alternative_service_str);
45 ProcessAlternativeService(session->http_server_properties(),
46 alternative_service_str, http_host_port_pair,
47 *session);
48 }
49 // If "Alt-Svc" is enabled, then ignore "Alternate-Protocol".
50 return;
51 }
52
53 if (!headers->HasHeader(kAlternateProtocolHeader))
54 return;
55
56 std::vector<std::string> alternate_protocol_values;
57 size_t iter = 0;
58 std::string alternate_protocol_str;
59 while (headers->EnumerateHeader(&iter, kAlternateProtocolHeader,
60 &alternate_protocol_str)) {
61 base::TrimWhitespaceASCII(alternate_protocol_str, base::TRIM_ALL,
62 &alternate_protocol_str);
63 if (!alternate_protocol_str.empty()) {
64 alternate_protocol_values.push_back(alternate_protocol_str);
65 }
66 }
67
68 ProcessAlternateProtocol(session->http_server_properties(),
69 alternate_protocol_values, http_host_port_pair,
70 *session);
71 }
72
73 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url,
74 HostPortPair* endpoint) {
75 const HostMappingRules* mapping_rules = GetHostMappingRules();
76 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) {
77 url::Replacements<char> replacements;
78 const std::string port_str = base::UintToString(endpoint->port());
79 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size()));
80 replacements.SetHost(endpoint->host().c_str(),
81 url::Component(0, endpoint->host().size()));
82 return url.ReplaceComponents(replacements);
83 }
84 return url;
85 }
86
87 HttpStreamFactory::HttpStreamFactory() {}
88
35 void HttpStreamFactory::ProcessAlternativeService( 89 void HttpStreamFactory::ProcessAlternativeService(
36 const base::WeakPtr<HttpServerProperties>& http_server_properties, 90 const base::WeakPtr<HttpServerProperties>& http_server_properties,
37 base::StringPiece alternative_service_str, 91 base::StringPiece alternative_service_str,
38 const HostPortPair& http_host_port_pair, 92 const HostPortPair& http_host_port_pair,
39 const HttpNetworkSession& session) { 93 const HttpNetworkSession& session) {
40 SpdyAltSvcWireFormat::AlternativeServiceVector alternative_service_vector; 94 SpdyAltSvcWireFormat::AlternativeServiceVector alternative_service_vector;
41 if (!SpdyAltSvcWireFormat::ParseHeaderFieldValue( 95 if (!SpdyAltSvcWireFormat::ParseHeaderFieldValue(
42 alternative_service_str, &alternative_service_vector)) { 96 alternative_service_str, &alternative_service_vector)) {
43 return; 97 return;
44 } 98 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 http_server_properties->ClearAlternativeServices(http_host_port_pair); 193 http_server_properties->ClearAlternativeServices(http_host_port_pair);
140 return; 194 return;
141 } 195 }
142 196
143 http_server_properties->SetAlternativeService( 197 http_server_properties->SetAlternativeService(
144 RewriteHost(http_host_port_pair), 198 RewriteHost(http_host_port_pair),
145 AlternativeService(protocol, "", static_cast<uint16_t>(port)), 199 AlternativeService(protocol, "", static_cast<uint16_t>(port)),
146 base::Time::Now() + base::TimeDelta::FromDays(30)); 200 base::Time::Now() + base::TimeDelta::FromDays(30));
147 } 201 }
148 202
149 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url,
150 HostPortPair* endpoint) {
151 const HostMappingRules* mapping_rules = GetHostMappingRules();
152 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) {
153 url::Replacements<char> replacements;
154 const std::string port_str = base::UintToString(endpoint->port());
155 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size()));
156 replacements.SetHost(endpoint->host().c_str(),
157 url::Component(0, endpoint->host().size()));
158 return url.ReplaceComponents(replacements);
159 }
160 return url;
161 }
162
163 HttpStreamFactory::HttpStreamFactory() {}
164
165 HostPortPair HttpStreamFactory::RewriteHost(HostPortPair host_port_pair) { 203 HostPortPair HttpStreamFactory::RewriteHost(HostPortPair host_port_pair) {
166 const HostMappingRules* mapping_rules = GetHostMappingRules(); 204 const HostMappingRules* mapping_rules = GetHostMappingRules();
167 if (mapping_rules) 205 if (mapping_rules)
168 mapping_rules->RewriteHost(&host_port_pair); 206 mapping_rules->RewriteHost(&host_port_pair);
169 return host_port_pair; 207 return host_port_pair;
170 } 208 }
171 209
172 } // namespace net 210 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory.h ('k') | net/spdy/spdy_test_util_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698