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

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

Issue 339663010: Add a probability to Alternate-Protocol support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Better plumbing Created 6 years, 5 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 | Annotate | Revision Log
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 "net/base/host_mapping_rules.h" 11 #include "net/base/host_mapping_rules.h"
11 #include "net/base/host_port_pair.h" 12 #include "net/base/host_port_pair.h"
12 #include "net/http/http_network_session.h" 13 #include "net/http/http_network_session.h"
13 #include "url/gurl.h" 14 #include "url/gurl.h"
14 15
15 namespace net { 16 namespace net {
16 17
17 // WARNING: If you modify or add any static flags, you must keep them in sync 18 // WARNING: If you modify or add any static flags, you must keep them in sync
18 // with |ResetStaticSettingsToInit|. This is critical for unit test isolation. 19 // with |ResetStaticSettingsToInit|. This is critical for unit test isolation.
19 20
20 // static 21 // static
21 bool HttpStreamFactory::spdy_enabled_ = true; 22 bool HttpStreamFactory::spdy_enabled_ = true;
22 23
23 HttpStreamFactory::~HttpStreamFactory() {} 24 HttpStreamFactory::~HttpStreamFactory() {}
24 25
25 // static 26 // static
26 void HttpStreamFactory::ResetStaticSettingsToInit() { 27 void HttpStreamFactory::ResetStaticSettingsToInit() {
27 spdy_enabled_ = true; 28 spdy_enabled_ = true;
28 } 29 }
29 30
30 void HttpStreamFactory::ProcessAlternateProtocol( 31 void HttpStreamFactory::ProcessAlternateProtocol(
31 const base::WeakPtr<HttpServerProperties>& http_server_properties, 32 const base::WeakPtr<HttpServerProperties>& http_server_properties,
32 const std::string& alternate_protocol_str, 33 const std::vector<std::string>& alternate_protocol_values,
33 const HostPortPair& http_host_port_pair, 34 const HostPortPair& http_host_port_pair,
34 const HttpNetworkSession& session) { 35 const HttpNetworkSession& session) {
35 std::vector<std::string> port_protocol_vector; 36 AlternateProtocol protocol = UNINITIALIZED_ALTERNATE_PROTOCOL;
36 base::SplitString(alternate_protocol_str, ':', &port_protocol_vector); 37 int port = 0;
37 if (port_protocol_vector.size() != 2) { 38 double probability = 1;
38 DVLOG(1) << kAlternateProtocolHeader 39 for (size_t i = 0; i < alternate_protocol_values.size(); ++i) {
ramant (doing other things) 2014/06/27 22:38:13 Small question: Can alternate_protocol_values have
Ryan Hamilton 2014/06/30 19:02:34 If a server said: Alternate-Protocol: 443:quic,44
ramant (doing other things) 2014/06/30 21:01:23 SGTM
39 << " header has too many tokens: " 40 const std::string& alternate_protocol_str = alternate_protocol_values[i];
40 << alternate_protocol_str; 41 if (StartsWithASCII(alternate_protocol_str, "p=", true)) {
41 return; 42 if (!base::StringToDouble(alternate_protocol_str.substr(2),
43 &probability) ||
44 probability < 0 || probability > 1) {
45 DVLOG(1) << kAlternateProtocolHeader
46 << " header has unrecognizable probability: "
47 << alternate_protocol_values[i];
48 return;
49 }
50 continue;
51 }
52
ramant (doing other things) 2014/06/27 22:38:13 nit: extra blank line.
Ryan Hamilton 2014/06/30 19:02:35 Done.
53
54 std::vector<std::string> port_protocol_vector;
55 base::SplitString(alternate_protocol_str, ':', &port_protocol_vector);
56 if (port_protocol_vector.size() != 2) {
57 DVLOG(1) << kAlternateProtocolHeader
58 << " header has too many tokens: "
59 << alternate_protocol_str;
60 return;
61 }
62
63 if (!base::StringToInt(port_protocol_vector[0], &port) ||
64 port <= 0 || port >= 1 << 16) {
65 DVLOG(1) << kAlternateProtocolHeader
66 << " header has unrecognizable port: "
67 << port_protocol_vector[0];
68 return;
69 }
70
71 protocol =
72 AlternateProtocolFromString(port_protocol_vector[1]);
73 if (IsAlternateProtocolValid(protocol) &&
74 !session.IsProtocolEnabled(protocol)) {
75 protocol = ALTERNATE_PROTOCOL_BROKEN;
76 }
77
78 if (protocol == ALTERNATE_PROTOCOL_BROKEN) {
79 DVLOG(1) << kAlternateProtocolHeader
80 << " header has unrecognized protocol: "
81 << port_protocol_vector[1];
82 return;
83 }
42 } 84 }
43 85
44 int port; 86 if (protocol == UNINITIALIZED_ALTERNATE_PROTOCOL)
45 if (!base::StringToInt(port_protocol_vector[0], &port) ||
46 port <= 0 || port >= 1 << 16) {
47 DVLOG(1) << kAlternateProtocolHeader
48 << " header has unrecognizable port: "
49 << port_protocol_vector[0];
50 return; 87 return;
51 }
52
53 AlternateProtocol protocol =
54 AlternateProtocolFromString(port_protocol_vector[1]);
55 if (IsAlternateProtocolValid(protocol) &&
56 !session.IsProtocolEnabled(protocol)) {
57 protocol = ALTERNATE_PROTOCOL_BROKEN;
58 }
59
60 if (protocol == ALTERNATE_PROTOCOL_BROKEN) {
61 DVLOG(1) << kAlternateProtocolHeader
62 << " header has unrecognized protocol: "
63 << port_protocol_vector[1];
64 return;
65 }
66 88
67 HostPortPair host_port(http_host_port_pair); 89 HostPortPair host_port(http_host_port_pair);
68 const HostMappingRules* mapping_rules = GetHostMappingRules(); 90 const HostMappingRules* mapping_rules = GetHostMappingRules();
69 if (mapping_rules) 91 if (mapping_rules)
70 mapping_rules->RewriteHost(&host_port); 92 mapping_rules->RewriteHost(&host_port);
71 93
72 if (http_server_properties->HasAlternateProtocol(host_port)) { 94 if (http_server_properties->HasAlternateProtocol(host_port)) {
73 const PortAlternateProtocolPair existing_alternate = 95 const AlternateProtocolInfo existing_alternate =
74 http_server_properties->GetAlternateProtocol(host_port); 96 http_server_properties->GetAlternateProtocol(host_port);
75 // If we think the alternate protocol is broken, don't change it. 97 // If we think the alternate protocol is broken, don't change it.
76 if (existing_alternate.protocol == ALTERNATE_PROTOCOL_BROKEN) 98 if (existing_alternate.protocol == ALTERNATE_PROTOCOL_BROKEN)
77 return; 99 return;
78 } 100 }
79 101 http_server_properties->SetAlternateProtocol(host_port, port, protocol,
80 http_server_properties->SetAlternateProtocol(host_port, port, protocol); 102 probability);
81 } 103 }
82 104
83 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, 105 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url,
84 HostPortPair* endpoint) { 106 HostPortPair* endpoint) {
85 const HostMappingRules* mapping_rules = GetHostMappingRules(); 107 const HostMappingRules* mapping_rules = GetHostMappingRules();
86 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { 108 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) {
87 url::Replacements<char> replacements; 109 url::Replacements<char> replacements;
88 const std::string port_str = base::IntToString(endpoint->port()); 110 const std::string port_str = base::IntToString(endpoint->port());
89 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size())); 111 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size()));
90 replacements.SetHost(endpoint->host().c_str(), 112 replacements.SetHost(endpoint->host().c_str(),
91 url::Component(0, endpoint->host().size())); 113 url::Component(0, endpoint->host().size()));
92 return url.ReplaceComponents(replacements); 114 return url.ReplaceComponents(replacements);
93 } 115 }
94 return url; 116 return url;
95 } 117 }
96 118
97 HttpStreamFactory::HttpStreamFactory() {} 119 HttpStreamFactory::HttpStreamFactory() {}
98 120
99 } // namespace net 121 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698