Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set credentials: 'same-origin' on the precaching requests. #1293

Merged
merged 1 commit into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions infra/testing/sw-env-mocks/Request.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class Request {
this.url = url;
this.method = options.method || 'GET';
this.mode = options.mode || 'cors';
// See https://fetch.spec.whatwg.org/#concept-request-credentials-mode
this.credentials = options.credentials || (this.mode === 'navigate' ?
'include' : 'omit');
this.headers = new Headers(options.headers);

this._body = new Blob('body' in options ? [options.body] : []);
Expand Down
6 changes: 4 additions & 2 deletions packages/workbox-precaching/models/PrecacheEntry.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class PrecacheEntry {
this._originalInput = originalInput;
this._entryId = url;
this._revision = revision;
const requestAsCacheKey = new Request(url);
const requestAsCacheKey = new Request(url, {credentials: 'same-origin'});
this._cacheRequest = requestAsCacheKey;
this._networkRequest = shouldCacheBust ?
this._cacheBustRequest(requestAsCacheKey) : requestAsCacheKey;
Expand All @@ -53,7 +53,9 @@ export default class PrecacheEntry {
*/
_cacheBustRequest(request) {
let url = request.url;
const requestOptions = {};
const requestOptions = {
credentials: 'same-origin',
};
if ('cache' in Request.prototype) {
// Make use of the Request cache mode where we can.
// Reload skips the HTTP cache for outgoing requests and updates
Expand Down
1 change: 1 addition & 0 deletions test/workbox-background-sync/node/test-Queue.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ describe(`[workbox-background-sync] Queue`, function() {
'body',
'headers',
'mode',
'credentials',
]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,21 @@ describe(`[workbox-precaching] PrecacheController`, function() {
expect(fetchWrapper.fetch.args[0][2]).to.equal(testPlugins);
expect(cacheWrapper.put.args[0][3]).to.equal(testPlugins);
});

it(`it should set credentials: 'same-origin' on the precaching requests`, async function() {
sandbox.spy(fetchWrapper, 'fetch');

const precacheController = new PrecacheController();
const cacheList = [
'/index.1234.html',
];
precacheController.addToCacheList(cacheList);

await precacheController.install();

const request = fetchWrapper.fetch.args[0][0];
expect(request.credentials).to.eql('same-origin');
});
});

describe(`cleanup()`, function() {
Expand Down