diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-12 22:47:14 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-12 22:47:14 +0000 |
commit | b6a50183e21e21207f2dff4953d19aa5be62d166 (patch) | |
tree | 9a937074af7bb0c5ff9c1987f68a4055bb54762c /net/http | |
parent | 6402aaec3c045969b60ef7b782ce25992d07a70f (diff) | |
download | chromium_src-b6a50183e21e21207f2dff4953d19aa5be62d166.zip chromium_src-b6a50183e21e21207f2dff4953d19aa5be62d166.tar.gz chromium_src-b6a50183e21e21207f2dff4953d19aa5be62d166.tar.bz2 |
Add --host-rules support.
The format for --host-rules is identical to --host-resolver-rules.
The difference is that --host-rules affects the endpoint of the HttpNetworkTransaction, not just the host resolver. So, this means the host passed to the host resolver and the TCP connect(), the tunnel CONNECT, and the SOCKS connect will be different.
Review URL: http://codereview.chromium.org/2057007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47083 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_network_transaction.cc | 29 | ||||
-rw-r--r-- | net/http/http_network_transaction.h | 2 |
2 files changed, 23 insertions, 8 deletions
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc index 2381450..6ac135e 100644 --- a/net/http/http_network_transaction.cc +++ b/net/http/http_network_transaction.cc @@ -17,6 +17,7 @@ #include "build/build_config.h" #include "googleurl/src/gurl.h" #include "net/base/connection_type_histograms.h" +#include "net/base/host_mapping_rules.h" #include "net/base/io_buffer.h" #include "net/base/load_flags.h" #include "net/base/net_errors.h" @@ -48,6 +49,7 @@ namespace net { namespace { +const HostMappingRules* g_host_mapping_rules = NULL; const std::string* g_next_protos = NULL; bool g_use_alternate_protocols = false; @@ -194,16 +196,20 @@ void ProcessAlternateProtocol(const HttpResponseHeaders& headers, return; } - if (alternate_protocols->HasAlternateProtocolFor(http_host_port_pair)) { + HostPortPair host_port(http_host_port_pair); + if (g_host_mapping_rules) + g_host_mapping_rules->RewriteHost(&host_port); + + if (alternate_protocols->HasAlternateProtocolFor(host_port)) { const HttpAlternateProtocols::PortProtocolPair existing_alternate = - alternate_protocols->GetAlternateProtocolFor(http_host_port_pair); + alternate_protocols->GetAlternateProtocolFor(host_port); // If we think the alternate protocol is broken, don't change it. if (existing_alternate.protocol == HttpAlternateProtocols::BROKEN) return; } alternate_protocols->SetAlternateProtocolFor( - http_host_port_pair, port, HttpAlternateProtocols::NPN_SPDY_1); + host_port, port, HttpAlternateProtocols::NPN_SPDY_1); } class NetLogHttpRequestParameter : public NetLog::EventParameters { @@ -302,6 +308,14 @@ HttpNetworkTransaction::HttpNetworkTransaction(HttpNetworkSession* session) } // static +void HttpNetworkTransaction::SetHostMappingRules(const std::string& rules) { + HostMappingRules* host_mapping_rules = new HostMappingRules(); + host_mapping_rules->SetRulesFromString(rules); + delete g_host_mapping_rules; + g_host_mapping_rules = host_mapping_rules; +} + +// static void HttpNetworkTransaction::SetUseAlternateProtocols(bool value) { g_use_alternate_protocols = value; } @@ -725,6 +739,9 @@ int HttpNetworkTransaction::DoResolveProxy() { endpoint_ = HostPortPair(request_->url.HostNoBrackets(), request_->url.EffectiveIntPort()); + if (g_host_mapping_rules) + g_host_mapping_rules->RewriteHost(&endpoint_); + GURL alternate_endpoint; if (alternate_protocol_mode_ == kUnspecified) { @@ -1232,12 +1249,8 @@ int HttpNetworkTransaction::DoReadHeadersComplete(int result) { return OK; } - HostPortPair http_host_port_pair; - http_host_port_pair.host = request_->url.HostNoBrackets(); - http_host_port_pair.port = request_->url.EffectiveIntPort(); - ProcessAlternateProtocol(*response_.headers, - http_host_port_pair, + endpoint_, session_->mutable_alternate_protocols()); int rv = HandleAuthChallenge(); diff --git a/net/http/http_network_transaction.h b/net/http/http_network_transaction.h index 7b033e3..d9fed35 100644 --- a/net/http/http_network_transaction.h +++ b/net/http/http_network_transaction.h @@ -42,6 +42,8 @@ class HttpNetworkTransaction : public HttpTransaction { virtual ~HttpNetworkTransaction(); + static void SetHostMappingRules(const std::string& rules); + // Controls whether or not we use the Alternate-Protocol header. static void SetUseAlternateProtocols(bool value); |