diff options
author | rch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-08 18:59:31 +0000 |
---|---|---|
committer | rch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-08 18:59:31 +0000 |
commit | 2139cebc2a5ac7b1c6422f477ca809b2c3223d64 (patch) | |
tree | cf350c54925233492eed17359439cc905b6cba3a /net/http/http_stream_factory.cc | |
parent | db248c54114004e339c9e1b42d2f2486addd19fc (diff) | |
download | chromium_src-2139cebc2a5ac7b1c6422f477ca809b2c3223d64.zip chromium_src-2139cebc2a5ac7b1c6422f477ca809b2c3223d64.tar.gz chromium_src-2139cebc2a5ac7b1c6422f477ca809b2c3223d64.tar.bz2 |
Add a probability to Alternate-Protocol support. Can be enabled either via a field trial or a command line flag.
Review URL: https://codereview.chromium.org/339663010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@281777 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_stream_factory.cc')
-rw-r--r-- | net/http/http_stream_factory.cc | 82 |
1 files changed, 52 insertions, 30 deletions
diff --git a/net/http/http_stream_factory.cc b/net/http/http_stream_factory.cc index b60df85..e86d8f8 100644 --- a/net/http/http_stream_factory.cc +++ b/net/http/http_stream_factory.cc @@ -7,6 +7,7 @@ #include "base/logging.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" +#include "base/strings/string_util.h" #include "net/base/host_mapping_rules.h" #include "net/base/host_port_pair.h" #include "net/http/http_network_session.h" @@ -29,40 +30,60 @@ void HttpStreamFactory::ResetStaticSettingsToInit() { void HttpStreamFactory::ProcessAlternateProtocol( const base::WeakPtr<HttpServerProperties>& http_server_properties, - const std::string& alternate_protocol_str, + const std::vector<std::string>& alternate_protocol_values, const HostPortPair& http_host_port_pair, const HttpNetworkSession& session) { - std::vector<std::string> port_protocol_vector; - base::SplitString(alternate_protocol_str, ':', &port_protocol_vector); - if (port_protocol_vector.size() != 2) { - DVLOG(1) << kAlternateProtocolHeader - << " header has too many tokens: " - << alternate_protocol_str; - return; - } - - int port; - if (!base::StringToInt(port_protocol_vector[0], &port) || - port <= 0 || port >= 1 << 16) { - DVLOG(1) << kAlternateProtocolHeader - << " header has unrecognizable port: " - << port_protocol_vector[0]; - return; - } + AlternateProtocol protocol = UNINITIALIZED_ALTERNATE_PROTOCOL; + int port = 0; + double probability = 1; + for (size_t i = 0; i < alternate_protocol_values.size(); ++i) { + const std::string& alternate_protocol_str = alternate_protocol_values[i]; + if (StartsWithASCII(alternate_protocol_str, "p=", true)) { + if (!base::StringToDouble(alternate_protocol_str.substr(2), + &probability) || + probability < 0 || probability > 1) { + DVLOG(1) << kAlternateProtocolHeader + << " header has unrecognizable probability: " + << alternate_protocol_values[i]; + return; + } + continue; + } + + std::vector<std::string> port_protocol_vector; + base::SplitString(alternate_protocol_str, ':', &port_protocol_vector); + if (port_protocol_vector.size() != 2) { + DVLOG(1) << kAlternateProtocolHeader + << " header has too many tokens: " + << alternate_protocol_str; + return; + } - AlternateProtocol protocol = - AlternateProtocolFromString(port_protocol_vector[1]); - if (IsAlternateProtocolValid(protocol) && - !session.IsProtocolEnabled(protocol)) { - protocol = ALTERNATE_PROTOCOL_BROKEN; + if (!base::StringToInt(port_protocol_vector[0], &port) || + port <= 0 || port >= 1 << 16) { + DVLOG(1) << kAlternateProtocolHeader + << " header has unrecognizable port: " + << port_protocol_vector[0]; + return; + } + + protocol = + AlternateProtocolFromString(port_protocol_vector[1]); + if (IsAlternateProtocolValid(protocol) && + !session.IsProtocolEnabled(protocol)) { + protocol = ALTERNATE_PROTOCOL_BROKEN; + } + + if (protocol == ALTERNATE_PROTOCOL_BROKEN) { + DVLOG(1) << kAlternateProtocolHeader + << " header has unrecognized protocol: " + << port_protocol_vector[1]; + return; + } } - if (protocol == ALTERNATE_PROTOCOL_BROKEN) { - DVLOG(1) << kAlternateProtocolHeader - << " header has unrecognized protocol: " - << port_protocol_vector[1]; + if (protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) return; - } HostPortPair host_port(http_host_port_pair); const HostMappingRules* mapping_rules = GetHostMappingRules(); @@ -70,14 +91,15 @@ void HttpStreamFactory::ProcessAlternateProtocol( mapping_rules->RewriteHost(&host_port); if (http_server_properties->HasAlternateProtocol(host_port)) { - const PortAlternateProtocolPair existing_alternate = + const AlternateProtocolInfo existing_alternate = http_server_properties->GetAlternateProtocol(host_port); // If we think the alternate protocol is broken, don't change it. if (existing_alternate.protocol == ALTERNATE_PROTOCOL_BROKEN) return; } - http_server_properties->SetAlternateProtocol(host_port, port, protocol); + http_server_properties->SetAlternateProtocol(host_port, port, protocol, + probability); } GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, |