feat: add support for net requests to use the session cookie store (#22806)

* chore: refactor all the net specs to be async with better error handling (#22731)

* chore: fix net specs when rerunning locally (#22745)

* feat: add support for net requests to use the session cookie store (#22704)

* fix: allow net requests to use Same-Site cookies (#22788)
This commit is contained in:
Samuel Attard
2020-03-23 10:53:40 -07:00
committed by GitHub
parent 5a34ad4e21
commit 9b14ae770d
5 changed files with 751 additions and 841 deletions

View File

@@ -22,6 +22,9 @@ which the request is associated.
with which the request is associated. Defaults to the empty string. The
`session` option prevails on `partition`. Thus if a `session` is explicitly
specified, `partition` is ignored.
* `useSessionCookies` Boolean (optional) - Whether to send cookies with this
request from the provided session. This will make the `net` request's
cookie behavior match a `fetch` request. Default is `false`.
* `protocol` String (optional) - The protocol scheme in the form 'scheme:'.
Currently supported values are 'http:' or 'https:'. Defaults to 'http:'.
* `host` String (optional) - The server host provided as a concatenation of

View File

@@ -234,7 +234,8 @@ function parseOptions (options) {
method: method,
url: urlStr,
redirectPolicy,
extraHeaders: options.headers || {}
extraHeaders: options.headers || {},
useSessionCookies: options.useSessionCookies || false
};
for (const [name, value] of Object.entries(urlLoaderOptions.extraHeaders)) {
if (!_isValidHeaderName(name)) {

View File

@@ -16,6 +16,7 @@
#include "gin/object_template_builder.h"
#include "gin/wrappable.h"
#include "mojo/public/cpp/system/data_pipe_producer.h"
#include "net/base/load_flags.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/chunked_data_pipe_getter.mojom.h"
@@ -343,6 +344,7 @@ gin_helper::WrappableBase* SimpleURLLoaderWrapper::New(gin::Arguments* args) {
return nullptr;
}
auto request = std::make_unique<network::ResourceRequest>();
request->attach_same_site_cookies = true;
opts.Get("method", &request->method);
opts.Get("url", &request->url);
std::map<std::string, std::string> extra_headers;
@@ -357,6 +359,12 @@ gin_helper::WrappableBase* SimpleURLLoaderWrapper::New(gin::Arguments* args) {
}
}
bool use_session_cookies = false;
opts.Get("useSessionCookies", &use_session_cookies);
if (!use_session_cookies) {
request->load_flags |= net::LOAD_DO_NOT_SEND_COOKIES;
}
// Chromium filters headers using browser rules, while for net module we have
// every header passed.
request->report_raw_headers = true;

File diff suppressed because it is too large Load Diff

View File

@@ -45,17 +45,17 @@ ifdescribe(process.electronBinding('features').isExtensionsEnabled())('chrome ex
});
it('serializes a loaded extension', async () => {
const extensionPath = path.join(fixtures, 'extensions', 'red-bg')
const manifest = JSON.parse(fs.readFileSync(path.join(extensionPath, 'manifest.json'), 'utf-8'))
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`)
const extension = await customSession.loadExtension(extensionPath)
expect(extension.id).to.be.a('string')
expect(extension.name).to.be.a('string')
expect(extension.path).to.be.a('string')
expect(extension.version).to.be.a('string')
expect(extension.url).to.be.a('string')
expect(extension.manifest).to.deep.equal(manifest)
})
const extensionPath = path.join(fixtures, 'extensions', 'red-bg');
const manifest = JSON.parse(fs.readFileSync(path.join(extensionPath, 'manifest.json'), 'utf-8'));
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`);
const extension = await customSession.loadExtension(extensionPath);
expect(extension.id).to.be.a('string');
expect(extension.name).to.be.a('string');
expect(extension.path).to.be.a('string');
expect(extension.version).to.be.a('string');
expect(extension.url).to.be.a('string');
expect(extension.manifest).to.deep.equal(manifest);
});
it('removes an extension', async () => {
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`);