diff options
Diffstat (limited to 'net/http/http_stream_factory.cc')
-rw-r--r-- | net/http/http_stream_factory.cc | 70 |
1 files changed, 54 insertions, 16 deletions
diff --git a/net/http/http_stream_factory.cc b/net/http/http_stream_factory.cc index f61a317..6ea3224 100644 --- a/net/http/http_stream_factory.cc +++ b/net/http/http_stream_factory.cc @@ -13,6 +13,7 @@ #include "net/base/host_port_pair.h" #include "net/base/port_util.h" #include "net/http/http_network_session.h" +#include "net/http/http_response_headers.h" #include "net/quic/quic_protocol.h" #include "net/spdy/spdy_alt_svc_wire_format.h" #include "url/gurl.h" @@ -32,6 +33,59 @@ void HttpStreamFactory::ResetStaticSettingsToInit() { spdy_enabled_ = true; } +void HttpStreamFactory::ProcessAlternativeServices( + HttpNetworkSession* session, + const HttpResponseHeaders* headers, + const HostPortPair& http_host_port_pair) { + if (session->params().parse_alternative_services) { + if (headers->HasHeader(kAlternativeServiceHeader)) { + std::string alternative_service_str; + headers->GetNormalizedHeader(kAlternativeServiceHeader, + &alternative_service_str); + ProcessAlternativeService(session->http_server_properties(), + alternative_service_str, http_host_port_pair, + *session); + } + // If "Alt-Svc" is enabled, then ignore "Alternate-Protocol". + return; + } + + if (!headers->HasHeader(kAlternateProtocolHeader)) + return; + + std::vector<std::string> alternate_protocol_values; + size_t iter = 0; + std::string alternate_protocol_str; + while (headers->EnumerateHeader(&iter, kAlternateProtocolHeader, + &alternate_protocol_str)) { + base::TrimWhitespaceASCII(alternate_protocol_str, base::TRIM_ALL, + &alternate_protocol_str); + if (!alternate_protocol_str.empty()) { + alternate_protocol_values.push_back(alternate_protocol_str); + } + } + + ProcessAlternateProtocol(session->http_server_properties(), + alternate_protocol_values, http_host_port_pair, + *session); +} + +GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, + HostPortPair* endpoint) { + const HostMappingRules* mapping_rules = GetHostMappingRules(); + if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { + url::Replacements<char> replacements; + const std::string port_str = base::UintToString(endpoint->port()); + replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size())); + replacements.SetHost(endpoint->host().c_str(), + url::Component(0, endpoint->host().size())); + return url.ReplaceComponents(replacements); + } + return url; +} + +HttpStreamFactory::HttpStreamFactory() {} + void HttpStreamFactory::ProcessAlternativeService( const base::WeakPtr<HttpServerProperties>& http_server_properties, base::StringPiece alternative_service_str, @@ -146,22 +200,6 @@ void HttpStreamFactory::ProcessAlternateProtocol( base::Time::Now() + base::TimeDelta::FromDays(30)); } -GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, - HostPortPair* endpoint) { - const HostMappingRules* mapping_rules = GetHostMappingRules(); - if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { - url::Replacements<char> replacements; - const std::string port_str = base::UintToString(endpoint->port()); - replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size())); - replacements.SetHost(endpoint->host().c_str(), - url::Component(0, endpoint->host().size())); - return url.ReplaceComponents(replacements); - } - return url; -} - -HttpStreamFactory::HttpStreamFactory() {} - HostPortPair HttpStreamFactory::RewriteHost(HostPortPair host_port_pair) { const HostMappingRules* mapping_rules = GetHostMappingRules(); if (mapping_rules) |