Commit 62329321 authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

Remove unused network service custom proxy code

This is no longer needed with data reduction proxy being turned off.

This removes the logic for
(i) Adding/removing proxy-specific pre-cache and post-cache headers
(ii) Remembering redirect loops within proxy delegate and disabling
custom proxy on redirect loops.
(iii) Use of alternate proxies for http:// requests (this was a
hack to enable use of QUIC for custom proxies for http:// requests).
(iv) Remembering the last N custom proxy configurations
in proxy delegate.

Change-Id: I4ee0cca48c1d581e026738964cb9e7a27f57a92e
Bug: 1048736
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2101318
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarRobert Ogden <robertogden@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#752486}
parent 43180832
...@@ -186,14 +186,6 @@ class IsolatedPrerenderBrowserTest ...@@ -186,14 +186,6 @@ class IsolatedPrerenderBrowserTest
net::ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME); net::ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME);
EXPECT_FALSE(config->should_override_existing_config); EXPECT_FALSE(config->should_override_existing_config);
EXPECT_FALSE(config->allow_non_idempotent_methods); EXPECT_FALSE(config->allow_non_idempotent_methods);
EXPECT_FALSE(config->assume_https_proxies_support_quic);
EXPECT_TRUE(config->can_use_proxy_on_http_url_redirect_cycles);
EXPECT_TRUE(config->pre_cache_headers.IsEmpty());
EXPECT_TRUE(config->post_cache_headers.IsEmpty());
EXPECT_EQ(config->rules.proxies_for_http.size(), 0U);
EXPECT_EQ(config->rules.proxies_for_ftp.size(), 0U);
if (want_empty) { if (want_empty) {
EXPECT_EQ(config->rules.proxies_for_https.size(), 0U); EXPECT_EQ(config->rules.proxies_for_https.size(), 0U);
......
...@@ -74,11 +74,7 @@ class IsolatedPrerenderProxyConfiguratorTest : public testing::Test { ...@@ -74,11 +74,7 @@ class IsolatedPrerenderProxyConfiguratorTest : public testing::Test {
net::ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME); net::ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME);
EXPECT_FALSE(config->should_override_existing_config); EXPECT_FALSE(config->should_override_existing_config);
EXPECT_FALSE(config->allow_non_idempotent_methods); EXPECT_FALSE(config->allow_non_idempotent_methods);
EXPECT_FALSE(config->assume_https_proxies_support_quic);
EXPECT_TRUE(config->can_use_proxy_on_http_url_redirect_cycles);
EXPECT_TRUE(config->pre_cache_headers.IsEmpty());
EXPECT_TRUE(config->post_cache_headers.IsEmpty());
EXPECT_EQ(config->connect_tunnel_headers.ToString(), headers.ToString()); EXPECT_EQ(config->connect_tunnel_headers.ToString(), headers.ToString());
EXPECT_EQ(config->rules.proxies_for_http.size(), 0U); EXPECT_EQ(config->rules.proxies_for_http.size(), 0U);
......
...@@ -104,10 +104,6 @@ int NetworkServiceNetworkDelegate::OnBeforeStartTransaction( ...@@ -104,10 +104,6 @@ int NetworkServiceNetworkDelegate::OnBeforeStartTransaction(
net::URLRequest* request, net::URLRequest* request,
net::CompletionOnceCallback callback, net::CompletionOnceCallback callback,
net::HttpRequestHeaders* headers) { net::HttpRequestHeaders* headers) {
if (network_context_->proxy_delegate()) {
network_context_->proxy_delegate()->OnBeforeStartTransaction(request,
headers);
}
URLLoader* url_loader = URLLoader::ForRequest(*request); URLLoader* url_loader = URLLoader::ForRequest(*request);
if (url_loader) if (url_loader)
return url_loader->OnBeforeStartTransaction(std::move(callback), headers); return url_loader->OnBeforeStartTransaction(std::move(callback), headers);
...@@ -126,10 +122,6 @@ void NetworkServiceNetworkDelegate::OnBeforeSendHeaders( ...@@ -126,10 +122,6 @@ void NetworkServiceNetworkDelegate::OnBeforeSendHeaders(
const net::ProxyInfo& proxy_info, const net::ProxyInfo& proxy_info,
const net::ProxyRetryInfoMap& proxy_retry_info, const net::ProxyRetryInfoMap& proxy_retry_info,
net::HttpRequestHeaders* headers) { net::HttpRequestHeaders* headers) {
if (network_context_->proxy_delegate()) {
network_context_->proxy_delegate()->OnBeforeSendHeaders(request, proxy_info,
headers);
}
} }
int NetworkServiceNetworkDelegate::OnHeadersReceived( int NetworkServiceNetworkDelegate::OnHeadersReceived(
......
...@@ -14,13 +14,6 @@ ...@@ -14,13 +14,6 @@
namespace network { namespace network {
namespace { namespace {
// The maximum size of the two caches that contain the GURLs for which special
// handling is required.
constexpr size_t kMaxCacheSize = 15;
// The maximum number of previous configs to keep.
constexpr size_t kMaxPreviousConfigs = 2;
bool ApplyProxyConfigToProxyInfo(const net::ProxyConfig::ProxyRules& rules, bool ApplyProxyConfigToProxyInfo(const net::ProxyConfig::ProxyRules& rules,
const net::ProxyRetryInfoMap& proxy_retry_info, const net::ProxyRetryInfoMap& proxy_retry_info,
const GURL& url, const GURL& url,
...@@ -98,24 +91,6 @@ void MergeRequestHeaders(net::HttpRequestHeaders* out, ...@@ -98,24 +91,6 @@ void MergeRequestHeaders(net::HttpRequestHeaders* out,
} }
} }
bool IsURLBlockedForCustomProxy(const net::URLRequest& request) {
auto* url_loader = URLLoader::ForRequest(request);
if (url_loader && url_loader->GetProcessId() == 0 &&
static_cast<SpecialRoutingIDs>(url_loader->GetRenderFrameId()) ==
MSG_ROUTING_NONE) {
// The request is not initiated by navigation or renderer. Block the request
// from going through custom proxy. This is a temporary solution to fix the
// bypassed downloads when using the custom proxy. See crbug.com/953166.
// TODO(957215): Implement a better solution in download manager and remove
// this codepath
return true;
}
// If the last entry occurs earlier in the |url_chain|, then very likely there
// is a redirect cycle.
return std::find(request.url_chain().rbegin() + 1, request.url_chain().rend(),
request.url_chain().back()) != request.url_chain().rend();
}
} // namespace } // namespace
NetworkServiceProxyDelegate::NetworkServiceProxyDelegate( NetworkServiceProxyDelegate::NetworkServiceProxyDelegate(
...@@ -130,66 +105,6 @@ NetworkServiceProxyDelegate::NetworkServiceProxyDelegate( ...@@ -130,66 +105,6 @@ NetworkServiceProxyDelegate::NetworkServiceProxyDelegate(
proxy_config_ = mojom::CustomProxyConfig::New(); proxy_config_ = mojom::CustomProxyConfig::New();
} }
void NetworkServiceProxyDelegate::OnBeforeStartTransaction(
net::URLRequest* request,
net::HttpRequestHeaders* headers) {
if (!MayProxyURL(request->url()))
return;
if (!proxy_config_->can_use_proxy_on_http_url_redirect_cycles &&
MayHaveProxiedURL(request->url()) &&
request->url().SchemeIs(url::kHttpScheme) &&
IsURLBlockedForCustomProxy(*request)) {
redirect_loop_cache_.push_front(request->url());
if (previous_proxy_configs_.size() > kMaxCacheSize)
redirect_loop_cache_.pop_back();
}
// For other schemes, the headers can be added to the CONNECT request when
// establishing the secure tunnel instead, see OnBeforeHttp1TunnelRequest().
const bool scheme_is_http = request->url().SchemeIs(url::kHttpScheme);
if (scheme_is_http) {
MergeRequestHeaders(headers, proxy_config_->pre_cache_headers);
auto* url_loader = URLLoader::ForRequest(*request);
if (url_loader) {
MergeRequestHeaders(headers,
url_loader->custom_proxy_pre_cache_headers());
}
}
}
void NetworkServiceProxyDelegate::OnBeforeSendHeaders(
net::URLRequest* request,
const net::ProxyInfo& proxy_info,
net::HttpRequestHeaders* headers) {
// For other schemes, the headers can be added to the CONNECT request when
// establishing the secure tunnel instead, see OnBeforeHttp1TunnelRequest().
if (!request->url().SchemeIs(url::kHttpScheme))
return;
auto* url_loader = URLLoader::ForRequest(*request);
if (IsInProxyConfig(proxy_info.proxy_server())) {
MergeRequestHeaders(headers, proxy_config_->post_cache_headers);
if (url_loader) {
MergeRequestHeaders(headers,
url_loader->custom_proxy_post_cache_headers());
}
} else if (MayHaveProxiedURL(request->url())) {
for (const auto& kv : proxy_config_->pre_cache_headers.GetHeaderVector()) {
headers->RemoveHeader(kv.key);
}
if (url_loader) {
for (const auto& kv :
url_loader->custom_proxy_pre_cache_headers().GetHeaderVector()) {
headers->RemoveHeader(kv.key);
}
}
}
}
NetworkServiceProxyDelegate::~NetworkServiceProxyDelegate() {} NetworkServiceProxyDelegate::~NetworkServiceProxyDelegate() {}
void NetworkServiceProxyDelegate::OnResolveProxy( void NetworkServiceProxyDelegate::OnResolveProxy(
...@@ -200,18 +115,11 @@ void NetworkServiceProxyDelegate::OnResolveProxy( ...@@ -200,18 +115,11 @@ void NetworkServiceProxyDelegate::OnResolveProxy(
if (!EligibleForProxy(*result, method)) if (!EligibleForProxy(*result, method))
return; return;
// Check if using custom proxy for |url| can result in redirect loops.
std::deque<GURL>::const_iterator it =
std::find(redirect_loop_cache_.begin(), redirect_loop_cache_.end(), url);
if (it != redirect_loop_cache_.end())
return;
net::ProxyInfo proxy_info; net::ProxyInfo proxy_info;
if (ApplyProxyConfigToProxyInfo(proxy_config_->rules, proxy_retry_info, url, if (ApplyProxyConfigToProxyInfo(proxy_config_->rules, proxy_retry_info, url,
&proxy_info)) { &proxy_info)) {
DCHECK(!proxy_info.is_empty() && !proxy_info.is_direct()); DCHECK(!proxy_info.is_empty() && !proxy_info.is_direct());
result->OverrideProxyList(proxy_info.proxy_list()); result->OverrideProxyList(proxy_info.proxy_list());
GetAlternativeProxy(proxy_retry_info, result);
} }
} }
...@@ -234,11 +142,6 @@ net::Error NetworkServiceProxyDelegate::OnTunnelHeadersReceived( ...@@ -234,11 +142,6 @@ net::Error NetworkServiceProxyDelegate::OnTunnelHeadersReceived(
void NetworkServiceProxyDelegate::OnCustomProxyConfigUpdated( void NetworkServiceProxyDelegate::OnCustomProxyConfigUpdated(
mojom::CustomProxyConfigPtr proxy_config) { mojom::CustomProxyConfigPtr proxy_config) {
DCHECK(IsValidCustomProxyConfig(*proxy_config)); DCHECK(IsValidCustomProxyConfig(*proxy_config));
if (proxy_config_) {
previous_proxy_configs_.push_front(std::move(proxy_config_));
if (previous_proxy_configs_.size() > kMaxPreviousConfigs)
previous_proxy_configs_.pop_back();
}
proxy_config_ = std::move(proxy_config); proxy_config_ = std::move(proxy_config);
} }
...@@ -278,12 +181,6 @@ bool NetworkServiceProxyDelegate::IsInProxyConfig( ...@@ -278,12 +181,6 @@ bool NetworkServiceProxyDelegate::IsInProxyConfig(
if (RulesContainsProxy(proxy_config_->rules, proxy_server)) if (RulesContainsProxy(proxy_config_->rules, proxy_server))
return true; return true;
for (const auto& config : previous_proxy_configs_) {
if (RulesContainsProxy(config->rules, proxy_server)) {
return true;
}
}
return false; return false;
} }
...@@ -291,18 +188,6 @@ bool NetworkServiceProxyDelegate::MayProxyURL(const GURL& url) const { ...@@ -291,18 +188,6 @@ bool NetworkServiceProxyDelegate::MayProxyURL(const GURL& url) const {
return !proxy_config_->rules.empty(); return !proxy_config_->rules.empty();
} }
bool NetworkServiceProxyDelegate::MayHaveProxiedURL(const GURL& url) const {
if (!proxy_config_->rules.empty())
return true;
for (const auto& config : previous_proxy_configs_) {
if (!config->rules.empty())
return true;
}
return false;
}
bool NetworkServiceProxyDelegate::EligibleForProxy( bool NetworkServiceProxyDelegate::EligibleForProxy(
const net::ProxyInfo& proxy_info, const net::ProxyInfo& proxy_info,
const std::string& method) const { const std::string& method) const {
...@@ -319,26 +204,4 @@ bool NetworkServiceProxyDelegate::EligibleForProxy( ...@@ -319,26 +204,4 @@ bool NetworkServiceProxyDelegate::EligibleForProxy(
return true; return true;
} }
void NetworkServiceProxyDelegate::GetAlternativeProxy(
const net::ProxyRetryInfoMap& proxy_retry_info,
net::ProxyInfo* result) {
net::ProxyServer resolved_proxy_server = result->proxy_server();
DCHECK(resolved_proxy_server.is_valid());
if (!resolved_proxy_server.is_https() ||
!proxy_config_->assume_https_proxies_support_quic) {
return;
}
net::ProxyInfo alternative_proxy_info;
alternative_proxy_info.UseProxyServer(net::ProxyServer(
net::ProxyServer::SCHEME_QUIC, resolved_proxy_server.host_port_pair()));
alternative_proxy_info.DeprioritizeBadProxies(proxy_retry_info);
if (alternative_proxy_info.is_empty())
return;
result->SetAlternativeProxy(alternative_proxy_info.proxy_server());
}
} // namespace network } // namespace network
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
namespace net { namespace net {
class HttpRequestHeaders; class HttpRequestHeaders;
class ProxyResolutionService; class ProxyResolutionService;
class URLRequest;
} // namespace net } // namespace net
namespace network { namespace network {
...@@ -39,13 +38,6 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkServiceProxyDelegate ...@@ -39,13 +38,6 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkServiceProxyDelegate
proxy_resolution_service_ = proxy_resolution_service; proxy_resolution_service_ = proxy_resolution_service;
} }
// These methods are forwarded from the NetworkDelegate.
void OnBeforeStartTransaction(net::URLRequest* request,
net::HttpRequestHeaders* headers);
void OnBeforeSendHeaders(net::URLRequest* request,
const net::ProxyInfo& proxy_info,
net::HttpRequestHeaders* headers);
// net::ProxyDelegate implementation: // net::ProxyDelegate implementation:
void OnResolveProxy(const GURL& url, void OnResolveProxy(const GURL& url,
const std::string& method, const std::string& method,
...@@ -65,19 +57,11 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkServiceProxyDelegate ...@@ -65,19 +57,11 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkServiceProxyDelegate
// Whether the current config may proxy |url|. // Whether the current config may proxy |url|.
bool MayProxyURL(const GURL& url) const; bool MayProxyURL(const GURL& url) const;
// Whether the current config may have proxied |url| with the current config
// or a previous config.
bool MayHaveProxiedURL(const GURL& url) const;
// Whether the HTTP |method| with current |proxy_info| is eligible to be // Whether the HTTP |method| with current |proxy_info| is eligible to be
// proxied. // proxied.
bool EligibleForProxy(const net::ProxyInfo& proxy_info, bool EligibleForProxy(const net::ProxyInfo& proxy_info,
const std::string& method) const; const std::string& method) const;
// Fills the alternative proxy config in |result| if applicable.
void GetAlternativeProxy(const net::ProxyRetryInfoMap& proxy_retry_info,
net::ProxyInfo* result);
// mojom::CustomProxyConfigClient implementation: // mojom::CustomProxyConfigClient implementation:
void OnCustomProxyConfigUpdated( void OnCustomProxyConfigUpdated(
mojom::CustomProxyConfigPtr proxy_config) override; mojom::CustomProxyConfigPtr proxy_config) override;
...@@ -89,17 +73,6 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkServiceProxyDelegate ...@@ -89,17 +73,6 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkServiceProxyDelegate
mojom::CustomProxyConfigPtr proxy_config_; mojom::CustomProxyConfigPtr proxy_config_;
mojo::Receiver<mojom::CustomProxyConfigClient> receiver_; mojo::Receiver<mojom::CustomProxyConfigClient> receiver_;
// Cache of URLs for which the usage of custom proxy results
// in redirect loops. A container is used here since it's possible that
// at any given time, there are multiple URLs that result in redirect loops
// when fetched via the custom proxy.
std::deque<GURL> redirect_loop_cache_;
// We keep track of a limited number of previous configs so we can determine
// if a request used a custom proxy if the config happened to change during
// the request.
std::deque<mojom::CustomProxyConfigPtr> previous_proxy_configs_;
net::ProxyResolutionService* proxy_resolution_service_ = nullptr; net::ProxyResolutionService* proxy_resolution_service_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(NetworkServiceProxyDelegate); DISALLOW_COPY_AND_ASSIGN(NetworkServiceProxyDelegate);
......
...@@ -185,10 +185,6 @@ bool StructTraits< ...@@ -185,10 +185,6 @@ bool StructTraits<
!data.ReadFetchIntegrity(&out->fetch_integrity) || !data.ReadFetchIntegrity(&out->fetch_integrity) ||
!data.ReadRequestBody(&out->request_body) || !data.ReadRequestBody(&out->request_body) ||
!data.ReadThrottlingProfileId(&out->throttling_profile_id) || !data.ReadThrottlingProfileId(&out->throttling_profile_id) ||
!data.ReadCustomProxyPreCacheHeaders(
&out->custom_proxy_pre_cache_headers) ||
!data.ReadCustomProxyPostCacheHeaders(
&out->custom_proxy_post_cache_headers) ||
!data.ReadFetchWindowId(&out->fetch_window_id) || !data.ReadFetchWindowId(&out->fetch_window_id) ||
!data.ReadDevtoolsRequestId(&out->devtools_request_id) || !data.ReadDevtoolsRequestId(&out->devtools_request_id) ||
!data.ReadRecursivePrefetchToken(&out->recursive_prefetch_token) || !data.ReadRecursivePrefetchToken(&out->recursive_prefetch_token) ||
......
...@@ -87,8 +87,6 @@ TEST(URLRequestMojomTraitsTest, Roundtrips_ResourceRequest) { ...@@ -87,8 +87,6 @@ TEST(URLRequestMojomTraitsTest, Roundtrips_ResourceRequest) {
original.upgrade_if_insecure = true; original.upgrade_if_insecure = true;
original.is_revalidating = false; original.is_revalidating = false;
original.throttling_profile_id = base::UnguessableToken::Create(); original.throttling_profile_id = base::UnguessableToken::Create();
original.custom_proxy_pre_cache_headers.SetHeader("pre_x", "x_value");
original.custom_proxy_post_cache_headers.SetHeader("post_y", "y_value");
original.fetch_window_id = base::UnguessableToken::Create(); original.fetch_window_id = base::UnguessableToken::Create();
original.trusted_params = ResourceRequest::TrustedParams(); original.trusted_params = ResourceRequest::TrustedParams();
......
...@@ -86,40 +86,6 @@ struct CustomProxyConfig { ...@@ -86,40 +86,6 @@ struct CustomProxyConfig {
// case properly. // case properly.
bool allow_non_idempotent_methods = false; bool allow_non_idempotent_methods = false;
// Whether every HTTPS proxy in the custom proxy config can be assumed to
// also support QUIC. If this is true, the network service will try to
// establish an alternative QUIC stream to the proxy in parallel to the HTTPS
// stream in an attempt to use QUIC if possible.
bool assume_https_proxies_support_quic = false;
// Whether the custom proxy config can be used on HTTP URLs whose fetching
// causes redirect cycles. If set to false, network service will try to
// bypass custom proxies on HTTP requests whose fetching causes redirect
// cycles. In such cases, the request will be fetched directly once the
// redirect cycle is detected.
// TODO(https://crbug.com/945892): Remove this boolean once Network
// Servicification is fully launched.
bool can_use_proxy_on_http_url_redirect_cycles = true;
// The custom proxy can set these headers in this config which will be added
// to all requests using the proxy. This allows setting headers that may be
// privacy/security sensitive which we don't want to send to the renderer.
// Headers that require per-request logic can be added through the
// |custom_proxy_pre_cache_headers| and |custom_proxy_post_cache_headers|
// fields in ResourceRequest.
//
// Headers that will be set before the cache for http:// requests. If the
// request does not use a custom proxy, these headers will be removed before
// sending to the network. If a request already has one of these headers set,
// it may be overwritten if a custom proxy is used, or removed if a custom
// proxy is not used.
HttpRequestHeaders pre_cache_headers;
// Headers that will be set after the cache for http:// requests that are
// issued through a custom proxy. Headers here will overwrite matching
// headers on the request if a custom proxy is used.
HttpRequestHeaders post_cache_headers;
// For tunneled requests (https://, ws://, wss://), these headers are added // For tunneled requests (https://, ws://, wss://), these headers are added
// to the CONNECT request. Headers here will overwrite matching headers on // to the CONNECT request. Headers here will overwrite matching headers on
// the CONNECT request if a custom proxy is used. // the CONNECT request if a custom proxy is used.
......
...@@ -347,13 +347,6 @@ struct URLRequest { ...@@ -347,13 +347,6 @@ struct URLRequest {
// The profile ID of network conditions to throttle the network request. // The profile ID of network conditions to throttle the network request.
mojo_base.mojom.UnguessableToken? throttling_profile_id; mojo_base.mojom.UnguessableToken? throttling_profile_id;
// Headers that will be added pre and post cache for http:// requests if the
// network context uses the custom proxy for this request. The custom proxy
// is used for requests that match the custom proxy config, and would
// otherwise be made direct.
HttpRequestHeaders custom_proxy_pre_cache_headers;
HttpRequestHeaders custom_proxy_post_cache_headers;
// See https://fetch.spec.whatwg.org/#concept-request-window // See https://fetch.spec.whatwg.org/#concept-request-window
// //
// This is an opaque id of the original requestor of the resource, which might // This is an opaque id of the original requestor of the resource, which might
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment