Commit 08ae5044 authored by Pavel Feldman's avatar Pavel Feldman

DevTools: allow setting cookies from intercepted requests.

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_mojo
Change-Id: I64e98c4083329a77c0ca079a2781455a2df121a3
Reviewed-on: https://chromium-review.googlesource.com/1091456Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565443}
parent 6943fdf8
...@@ -18,12 +18,14 @@ ...@@ -18,12 +18,14 @@
#include "net/base/upload_bytes_element_reader.h" #include "net/base/upload_bytes_element_reader.h"
#include "net/base/upload_element_reader.h" #include "net/base/upload_element_reader.h"
#include "net/cert/cert_status_flags.h" #include "net/cert/cert_status_flags.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_options.h"
#include "net/cookies/cookie_store.h"
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
#include "net/http/http_util.h" #include "net/http/http_util.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
#include "third_party/blink/public/platform/resource_request_blocked_reason.h" #include "third_party/blink/public/platform/resource_request_blocked_reason.h"
namespace { namespace {
static const int kInitialBufferSize = 4096; static const int kInitialBufferSize = 4096;
static const int kMaxBufferSize = IPC::Channel::kMaximumMessageSize / 4; static const int kMaxBufferSize = IPC::Channel::kMaximumMessageSize / 4;
...@@ -1102,6 +1104,33 @@ void DevToolsURLInterceptorRequestJob::ProcessInterceptionResponse( ...@@ -1102,6 +1104,33 @@ void DevToolsURLInterceptorRequestJob::ProcessInterceptionResponse(
interceptor_->ExpectRequestAfterRedirect(request(), interception_id_); interceptor_->ExpectRequestAfterRedirect(request(), interception_id_);
} }
// Set cookies in the network stack.
net::CookieOptions options;
options.set_include_httponly();
base::Time response_date;
if (!mock_response_details_->response_headers()->GetDateValue(
&response_date)) {
response_date = base::Time();
}
options.set_server_time(response_date);
const base::StringPiece name("Set-Cookie");
std::string cookie_line;
size_t iter = 0;
while (mock_response_details_->response_headers()->EnumerateHeader(
&iter, name, &cookie_line)) {
std::unique_ptr<net::CanonicalCookie> cookie =
net::CanonicalCookie::Create(request_details_.url, cookie_line,
base::Time::Now(), options);
if (!cookie)
continue;
auto* store = request_details_.url_request_context->cookie_store();
store->SetCanonicalCookieAsync(
std::move(cookie), request_details_.url.SchemeIsCryptographic(),
!options.exclude_httponly(), net::CookieStore::SetCookiesCallback());
}
if (sub_request_) { if (sub_request_) {
sub_request_->Cancel(); sub_request_->Cancel();
sub_request_.reset(); sub_request_.reset();
......
...@@ -24,3 +24,4 @@ crbug.com/800898 external/wpt/FileAPI/url/url-in-tags-revoke.window.html [ Pass ...@@ -24,3 +24,4 @@ crbug.com/800898 external/wpt/FileAPI/url/url-in-tags-revoke.window.html [ Pass
# Flaky on non-NetworkService (disabled), consistent failing on NetworkService. Probably due to DCHECK. # Flaky on non-NetworkService (disabled), consistent failing on NetworkService. Probably due to DCHECK.
crbug.com/849670 http/tests/devtools/service-workers/service-worker-v8-cache.js [ Pass Failure ] crbug.com/849670 http/tests/devtools/service-workers/service-worker-v8-cache.js [ Pass Failure ]
crbug.com/850689 http/tests/inspector-protocol/network/interception-set-cookie.js [ Failure ]
Tests that intercepted resonses can set cookies.
cookie: my_special_cookie=no_domain
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(
`Tests that intercepted resonses can set cookies.`);
await session.protocol.Network.enable();
await session.protocol.Runtime.enable();
await dp.Network.setRequestInterception({patterns: [{}]});
dp.Network.onRequestIntercepted(e => {
const response = [
'HTTP/1.1 200 OK',
'Set-Cookie: my_special_cookie=no_domain',
'Content-Type: text/html',
'',
'<html>Hello world</html>'];
const rawResponse = btoa(response.join('\r\n'));
dp.Network.continueInterceptedRequest({interceptionId: e.params.interceptionId, rawResponse});
});
dp.Page.navigate({url: 'http://127.0.0.1:8000/inspector-protocol/network/resources/simple.html'});
await dp.Network.onceLoadingFinished();
testRunner.log(`cookie: ${(await session.evaluate("document.cookie"))}`);
testRunner.completeTest();
})
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