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

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: 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,
Ryan Hamilton 2016/03/18 20:54:58 Does this method need to move as part of this CL?
xunjieli 2016/03/18 21:01:27 I was tricked too! The diffing tool is being weird
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 http_server_properties->ClearAlternativeServices(http_host_port_pair); 188 http_server_properties->ClearAlternativeServices(http_host_port_pair);
135 return; 189 return;
136 } 190 }
137 191
138 http_server_properties->SetAlternativeService( 192 http_server_properties->SetAlternativeService(
139 RewriteHost(http_host_port_pair), 193 RewriteHost(http_host_port_pair),
140 AlternativeService(protocol, "", static_cast<uint16_t>(port)), 194 AlternativeService(protocol, "", static_cast<uint16_t>(port)),
141 base::Time::Now() + base::TimeDelta::FromDays(30)); 195 base::Time::Now() + base::TimeDelta::FromDays(30));
142 } 196 }
143 197
144 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url,
145 HostPortPair* endpoint) {
146 const HostMappingRules* mapping_rules = GetHostMappingRules();
147 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) {
148 url::Replacements<char> replacements;
149 const std::string port_str = base::UintToString(endpoint->port());
150 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size()));
151 replacements.SetHost(endpoint->host().c_str(),
152 url::Component(0, endpoint->host().size()));
153 return url.ReplaceComponents(replacements);
154 }
155 return url;
156 }
157
158 HttpStreamFactory::HttpStreamFactory() {}
159
160 HostPortPair HttpStreamFactory::RewriteHost(HostPortPair host_port_pair) { 198 HostPortPair HttpStreamFactory::RewriteHost(HostPortPair host_port_pair) {
161 const HostMappingRules* mapping_rules = GetHostMappingRules(); 199 const HostMappingRules* mapping_rules = GetHostMappingRules();
162 if (mapping_rules) 200 if (mapping_rules)
163 mapping_rules->RewriteHost(&host_port_pair); 201 mapping_rules->RewriteHost(&host_port_pair);
164 return host_port_pair; 202 return host_port_pair;
165 } 203 }
166 204
167 } // namespace net 205 } // 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