Commit 9bfe4996 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Make URLRequest::proxy_server available through network::ResourceResponseInfo

This is a preparation CL for bug 879777, where
data_reduction_proxy::WarmupURLFetcher is being migrated away from
URLFetcher in favor of SimpleURLLoader.

WarmupURLFetcher unittests' correctness relies on checking whether
the appropriate net::ProxyServer instance is used.
This CL makes this information available through network::ResourceResponseInfo.

Note that, because it is a non-trivial c++ object, an specific IPC trait
was implemented, so that the object can be passed across mojo pipes.

BUG=879777

Cq-Include-Trybots: luci.chromium.try:linux_mojo
Change-Id: I3728ba3173a23ad59dd3bf00877d7b1131944488
Reviewed-on: https://chromium-review.googlesource.com/c/1251642Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#596327}
parent 9d90876b
......@@ -3760,6 +3760,72 @@ TEST_F(NetworkContextTest, ProxyErrorClientNotifiedOfPacError) {
"Failed: FindProxyForURL(url=http://server.bad.dns/)");
}
// Test ensures that ProxyServer data is populated correctly across Mojo calls.
// Basically it performs a set of URLLoader network requests, whose requests
// configure proxies. Then it checks whether the expected proxy scheme is
// respected.
TEST_F(NetworkContextTest, EnsureProperProxyServerIsUsed) {
net::test_server::EmbeddedTestServer test_server;
test_server.AddDefaultHandlers(
base::FilePath(FILE_PATH_LITERAL("services/test/data")));
ASSERT_TRUE(test_server.Start());
struct ProxyConfigSet {
net::ProxyConfig proxy_config;
GURL url;
net::ProxyServer::Scheme expected_proxy_config_scheme;
} proxy_config_set[2];
proxy_config_set[0].proxy_config.proxy_rules().ParseFromString(
base::StringPrintf("http=%s",
test_server.host_port_pair().ToString().c_str()));
// The domain here is irrelevant, and it is the path that matters.
proxy_config_set[0].url = GURL("http://does.not.matter/echo");
proxy_config_set[0].expected_proxy_config_scheme =
net::ProxyServer::SCHEME_HTTP;
proxy_config_set[1].proxy_config.proxy_rules().ParseFromString(
"http=direct://");
proxy_config_set[1].url = test_server.GetURL("/echo");
proxy_config_set[1].expected_proxy_config_scheme =
net::ProxyServer::SCHEME_DIRECT;
for (const auto& proxy_data : proxy_config_set) {
mojom::NetworkContextParamsPtr context_params = CreateContextParams();
context_params->initial_proxy_config = net::ProxyConfigWithAnnotation(
proxy_data.proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS);
mojom::ProxyConfigClientPtr config_client;
context_params->proxy_config_client_request =
mojo::MakeRequest(&config_client);
std::unique_ptr<NetworkContext> network_context =
CreateContextWithParams(std::move(context_params));
mojom::URLLoaderFactoryPtr loader_factory;
mojom::URLLoaderFactoryParamsPtr params =
mojom::URLLoaderFactoryParams::New();
params->process_id = 0;
network_context->CreateURLLoaderFactory(mojo::MakeRequest(&loader_factory),
std::move(params));
ResourceRequest request;
// The domain here is irrelevant, and it is the path that matters.
request.url = proxy_data.url; // test_server.GetURL("/echo");
mojom::URLLoaderPtr loader;
TestURLLoaderClient client;
loader_factory->CreateLoaderAndStart(
mojo::MakeRequest(&loader), 0 /* routing_id */, 0 /* request_id */,
0 /* options */, request, client.CreateInterfacePtr(),
net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS));
client.RunUntilComplete();
EXPECT_TRUE(client.has_received_completion());
EXPECT_EQ(client.response_head().proxy_server.scheme(),
proxy_data.expected_proxy_config_scheme);
}
}
} // namespace
} // namespace network
......@@ -222,6 +222,47 @@ void ParamTraits<scoped_refptr<net::HttpResponseHeaders>>::Log(
l->append("<HttpResponseHeaders>");
}
void ParamTraits<net::ProxyServer>::Write(base::Pickle* m,
const param_type& p) {
net::ProxyServer::Scheme scheme = p.scheme();
WriteParam(m, scheme);
// When scheme is either 'direct' or 'invalid' |host_port_pair|
// should not be called, as per the method implementation body.
if (scheme != net::ProxyServer::SCHEME_DIRECT &&
scheme != net::ProxyServer::SCHEME_INVALID) {
WriteParam(m, p.host_port_pair());
}
WriteParam(m, p.is_trusted_proxy());
}
bool ParamTraits<net::ProxyServer>::Read(const base::Pickle* m,
base::PickleIterator* iter,
param_type* r) {
net::ProxyServer::Scheme scheme;
bool is_trusted_proxy = false;
if (!ReadParam(m, iter, &scheme))
return false;
// When scheme is either 'direct' or 'invalid' |host_port_pair|
// should not be called, as per the method implementation body.
net::HostPortPair host_port_pair;
if (scheme != net::ProxyServer::SCHEME_DIRECT &&
scheme != net::ProxyServer::SCHEME_INVALID &&
!ReadParam(m, iter, &host_port_pair)) {
return false;
}
if (!ReadParam(m, iter, &is_trusted_proxy))
return false;
*r = net::ProxyServer(scheme, host_port_pair, is_trusted_proxy);
return true;
}
void ParamTraits<net::ProxyServer>::Log(const param_type& p, std::string* l) {
l->append("<ProxyServer>");
}
void ParamTraits<net::OCSPVerifyResult>::Write(base::Pickle* m,
const param_type& p) {
WriteParam(m, p.response_status);
......
......@@ -13,6 +13,7 @@
#include "ipc/param_traits_macros.h"
#include "net/base/auth.h"
#include "net/base/host_port_pair.h"
#include "net/base/proxy_server.h"
#include "net/base/request_priority.h"
#include "net/cert/cert_verify_result.h"
#include "net/cert/ct_policy_status.h"
......@@ -112,6 +113,16 @@ struct COMPONENT_EXPORT(NETWORK_CPP_BASE) ParamTraits<net::HttpRequestHeaders> {
static void Log(const param_type& p, std::string* l);
};
template <>
struct COMPONENT_EXPORT(NETWORK_CPP_BASE) ParamTraits<net::ProxyServer> {
typedef net::ProxyServer param_type;
static void Write(base::Pickle* m, const param_type& p);
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
param_type* r);
static void Log(const param_type& p, std::string* l);
};
template <>
struct COMPONENT_EXPORT(NETWORK_CPP_BASE) ParamTraits<net::OCSPVerifyResult> {
typedef net::OCSPVerifyResult param_type;
......@@ -203,6 +214,9 @@ struct COMPONENT_EXPORT(NETWORK_CPP_BASE) ParamTraits<url::Origin> {
IPC_ENUM_TRAITS_MAX_VALUE(
net::ct::CTPolicyCompliance,
net::ct::CTPolicyCompliance::CT_POLICY_COMPLIANCE_DETAILS_NOT_AVAILABLE)
IPC_ENUM_TRAITS(net::ProxyServer::Scheme); // BitMask.
IPC_ENUM_TRAITS_MAX_VALUE(net::OCSPVerifyResult::ResponseStatus,
net::OCSPVerifyResult::PARSE_RESPONSE_DATA_ERROR)
IPC_ENUM_TRAITS_MAX_VALUE(net::OCSPRevocationStatus,
......
......@@ -13,6 +13,7 @@
#include "ipc/param_traits_macros.h"
#include "net/base/auth.h"
#include "net/base/host_port_pair.h"
#include "net/base/proxy_server.h"
#include "net/base/request_priority.h"
#include "net/cert/cert_verify_result.h"
#include "net/cert/ct_policy_status.h"
......@@ -193,6 +194,7 @@ IPC_STRUCT_TRAITS_BEGIN(network::ResourceResponseInfo)
IPC_STRUCT_TRAITS_MEMBER(alpn_negotiated_protocol)
IPC_STRUCT_TRAITS_MEMBER(socket_address)
IPC_STRUCT_TRAITS_MEMBER(was_fetched_via_cache)
IPC_STRUCT_TRAITS_MEMBER(proxy_server)
IPC_STRUCT_TRAITS_MEMBER(was_fetched_via_service_worker)
IPC_STRUCT_TRAITS_MEMBER(was_fallback_required_by_service_worker)
IPC_STRUCT_TRAITS_MEMBER(url_list_via_service_worker)
......
......@@ -15,6 +15,7 @@
#include "base/time/time.h"
#include "net/base/host_port_pair.h"
#include "net/base/load_timing_info.h"
#include "net/base/proxy_server.h"
#include "net/cert/ct_policy_status.h"
#include "net/cert/signed_certificate_timestamp_and_status.h"
#include "net/http/http_response_headers.h"
......@@ -114,6 +115,9 @@ struct COMPONENT_EXPORT(NETWORK_CPP_BASE) ResourceResponseInfo {
// True if the response was delivered through a proxy.
bool was_fetched_via_proxy;
// The proxy server used for this request, if any.
net::ProxyServer proxy_server;
// True if the response was fetched by a ServiceWorker.
bool was_fetched_via_service_worker;
......
......@@ -68,6 +68,7 @@ void PopulateResourceResponse(net::URLRequest* request,
response->head.socket_address = response_info.socket_address;
response->head.was_fetched_via_cache = request->was_cached();
response->head.was_fetched_via_proxy = request->was_fetched_via_proxy();
response->head.proxy_server = request->proxy_server();
response->head.network_accessed = response_info.network_accessed;
response->head.async_revalidation_requested =
response_info.async_revalidation_requested;
......
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