Skip to content

Commit

Permalink
Plumb raw headers when intercepting a request
Browse files Browse the repository at this point in the history
This CL ensures that |RequestHeadersCallback| and |ResponseHeadersCallback|
are proxied from the |URLRequest| to the |DevToolsURLInterceptorJob::SubRequest|
when intercepting a request.

This allows the SubRequest to receive SPDY/QUIC internal headers, as well as plain HTTP raw headers.

BUG=806281
R=caseq@chromium.org

Change-Id: Id152c63426468ab7637d2885dad7b91f124b54aa
Reviewed-on: https://chromium-review.googlesource.com/916901
Commit-Queue: Andrey Kosyakov <caseq@chromium.org>
Reviewed-by: Andrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537971}
  • Loading branch information
vempatiy authored and Commit Bot committed Feb 21, 2018
1 parent 20e6b06 commit d15f52c
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ Yan Wang <yan0422.wang@samsung.com>
Yang Gu <yang.gu@intel.com>
Yannic Bonenberger <contact@yannic-bonenberger.com>
Yarin Kaul <yarin.kaul@gmail.com>
Yash Vempati <vempatiy@amazon.com>
Ye Liu <cbakgly@gmail.com>
Yeol Park <peary2@gmail.com>
Yi Shen <yi.shen@samsung.com>
Expand Down
14 changes: 14 additions & 0 deletions content/browser/devtools/devtools_url_interceptor_request_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ DevToolsURLInterceptorRequestJob::SubRequest::SubRequest(
request_->SetExtraRequestHeaders(request_details.extra_request_headers);
request_->SetReferrer(request_details.referrer);
request_->set_referrer_policy(request_details.referrer_policy);
request_->SetRequestHeadersCallback(
devtools_interceptor_request_job->request_headers_callback_);
request_->SetResponseHeadersCallback(
devtools_interceptor_request_job->response_headers_callback_);

// Mimic the ResourceRequestInfoImpl of the original request.
const ResourceRequestInfoImpl* resource_request_info =
Expand Down Expand Up @@ -1154,6 +1158,16 @@ bool DevToolsURLInterceptorRequestJob::ProcessAuthRespose(
return false;
}

void DevToolsURLInterceptorRequestJob::SetRequestHeadersCallback(
net::RequestHeadersCallback callback) {
request_headers_callback_ = callback;
}

void DevToolsURLInterceptorRequestJob::SetResponseHeadersCallback(
net::ResponseHeadersCallback callback) {
response_headers_callback_ = callback;
}

DevToolsURLInterceptorRequestJob::RequestDetails::RequestDetails(
const GURL& url,
const std::string& method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "content/browser/devtools/protocol/network.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/resource_type.h"
#include "net/http/http_raw_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_job.h"

Expand Down Expand Up @@ -56,6 +58,9 @@ class DevToolsURLInterceptorRequestJob : public net::URLRequestJob {

void SetAuth(const net::AuthCredentials& credentials) override;
void CancelAuth() override;
void SetRequestHeadersCallback(net::RequestHeadersCallback callback) override;
void SetResponseHeadersCallback(
net::ResponseHeadersCallback callback) override;

// Must be called on IO thread.
void StopIntercepting();
Expand Down Expand Up @@ -154,6 +159,8 @@ class DevToolsURLInterceptorRequestJob : public net::URLRequestJob {
std::vector<std::unique_ptr<GetResponseBodyForInterceptionCallback>>
pending_body_requests_;

net::RequestHeadersCallback request_headers_callback_;
net::ResponseHeadersCallback response_headers_callback_;
base::WeakPtrFactory<DevToolsURLInterceptorRequestJob> weak_ptr_factory_;

DISALLOW_COPY_AND_ASSIGN(DevToolsURLInterceptorRequestJob);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Network.requestIntercepted ID 2 302 redirect redirect2.pl -> redirect3.pl
allowRequest ID 2
Network.requestIntercepted ID 2 301 redirect redirect3.pl -> final.js
mockResponse ID 2
Network.responseReceived redirect3.pl 200 application/javascript
Network.responseReceived redirect3.pl 301 application/javascript
Page.frameStoppedLoading
Hello from the mock resource

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Tests that raw response headers are correctly reported in case of interception.
Test started
Network agent enabled
Request interception enabled
Page agent enabled
Runtime agent enabled
Response.requestHeadersText present: true
Connection raw header present: true
Network.requestIntercepted ID 1 GET simple-iframe.html type: Document
allowRequest ID 1
Network.responseReceived simple-iframe.html 200 text/html
Page.frameStoppedLoading

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(
`Tests that raw response headers are correctly reported in case of interception.`);

var InterceptionHelper = await testRunner.loadScript('../resources/interception-test.js');
var helper = new InterceptionHelper(testRunner, session);

var requestInterceptedDict = {
'simple-iframe.html': event => helper.allowRequest(event),
};

await helper.startInterceptionTest(requestInterceptedDict);
session.evaluate(`
var iframe = document.createElement('iframe');
iframe.src = '${testRunner.url('./resources/simple-iframe.html')}';
document.body.appendChild(iframe);
`);

await dp.Network.onResponseReceived(event => {
const response = event.params.response;
const haveRequestHeadersText = response.requestHeadersText;
const splitRawHeaders = response.requestHeadersText.split('\r\n');
const connectionHeaderPresent = splitRawHeaders.filter(header => header.includes('Connection'));

testRunner.log(`Response.requestHeadersText present: ${!!haveRequestHeadersText}`);
testRunner.log(`Connection raw header present: ${!!connectionHeaderPresent.length}`);
});
})

0 comments on commit d15f52c

Please sign in to comment.