Allow extensions to modify CORS preflight with Web Request API (1/2)
Supporting preflight is tricky because preflight requests are made in
the network service, and they don't have request IDs. We are adding
a new message, OnLoaderForCorsPreflightCreated, to
TrustedURLLoaderHeaderClient to address that.
We are using TrustedURLLoaderHeaderClient, which means this mechanism
works only when "extraHeaders" is specified. Unlike for usual requests,
WebRequestProxyingUrlLoaderFactory::InProgressRequest dispatches
- onBeforeRequest when OnLoaderForCorsPreflightCreated is called,
- onBeforeSendHeaders and onSendHeaders when OnBeforeSendHeaders
is called, and
- onHeadersReceived, onResponseStarted, and onCompleted when
OnHeadersReceived is called.
This CL is a preliminary change. It adds
- TrustedURLLoaderHeaderClient.OnLoaderForCorsPreflightCreated
as described above,
- "remote_endpoint" param to TrustedHeaderClient.OnHeadersReceived
to get endpoint information in OnHeadersReceived, and
- kURLLoaderOptionAsCorsPreflight to mark a request as a CORS
preflight.
This CL doesn't change any behavior because we have not set
kURLLoadOptionAsCorsPreflight and kURLLoadOptionUseHeaderClient in
network::cors::PreflightController yet.
The subsequent change is: https://crrev.com/c/1837561
Bug: 1002884
Change-Id: Ib396e35ce636f6ed016df089d393dedec94db430
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1833395
Commit-Queue: Yutaka Hirano <[email protected]>
Reviewed-by: David Benjamin <[email protected]>
Reviewed-by: Karan Bhatia <[email protected]>
Reviewed-by: Kinuko Yasuda <[email protected]>
Reviewed-by: Takashi Toyoshima <[email protected]>
Cr-Commit-Position: refs/heads/master@{#706372}
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index eccaeff..1f133bb 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -910,6 +910,9 @@
// |NetworkDelegate::URLRequestDestroyed()| has been called.
OnCallToDelegate(NetLogEventType::NETWORK_DELEGATE_HEADERS_RECEIVED);
allowed_unsafe_redirect_url_ = GURL();
+ IPEndPoint endpoint;
+ if (transaction_)
+ transaction_->GetRemoteEndpoint(&endpoint);
// The NetworkDelegate must watch for OnRequestDestroyed and not modify
// any of the arguments after it's called.
// TODO(mattm): change the API to remove the out-params and take the
@@ -918,7 +921,7 @@
request_,
base::BindOnce(&URLRequestHttpJob::OnHeadersReceivedCallback,
weak_factory_.GetWeakPtr()),
- headers.get(), &override_response_headers_,
+ headers.get(), &override_response_headers_, endpoint,
&allowed_unsafe_redirect_url_);
if (error != OK) {
if (error == ERR_IO_PENDING) {