-
-
Notifications
You must be signed in to change notification settings - Fork 664
fetch: send 'sec-purpose' header for prefetch requests #3694
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,8 @@ const { | |
requestMode, | ||
requestCredentials, | ||
requestCache, | ||
requestDuplex | ||
requestDuplex, | ||
requestInitiator | ||
} = require('./constants') | ||
const { kEnumerableProperty, normalizedMethodRecordsBase, normalizedMethodRecords } = util | ||
const { webidl } = require('./webidl') | ||
|
@@ -136,7 +137,7 @@ class Request { | |
} | ||
|
||
// 4. Set request to a new request whose URL is parsedURL. | ||
request = makeRequest({ urlList: [parsedURL] }) | ||
request = makeRequest({ urlList: [parsedURL], ...init }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @KhafraDev Is this right??? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is wrong |
||
|
||
// 5. Set fallbackMode to "cors". | ||
fallbackMode = 'cors' | ||
|
@@ -215,6 +216,8 @@ class Request { | |
redirect: request.redirect, | ||
// integrity metadata request’s integrity metadata. | ||
integrity: request.integrity, | ||
// initiator metadata request’s initiator metadata. | ||
initiator: request.initiator, | ||
// keepalive request’s keepalive. | ||
keepalive: request.keepalive, | ||
// reload-navigation flag request’s reload-navigation flag. | ||
|
@@ -1057,6 +1060,12 @@ webidl.converters.RequestInit = webidl.dictionaryConverter([ | |
key: 'integrity', | ||
converter: webidl.converters.DOMString | ||
}, | ||
{ | ||
key: 'initiator', | ||
converter: webidl.converters.DOMString, | ||
// https://fetch.spec.whatwg.org/#requestcache | ||
Uzlopak marked this conversation as resolved.
Show resolved
Hide resolved
Uzlopak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
allowedValues: requestInitiator | ||
}, | ||
{ | ||
key: 'keepalive', | ||
converter: webidl.converters.boolean | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict' | ||
|
||
const { test, describe, before, after } = require('node:test') | ||
const assert = require('node:assert') | ||
const events = require('node:events') | ||
const http = require('node:http') | ||
const { fetch, Request } = require('../../') | ||
const { closeServerAsPromise } = require('../utils/node-http') | ||
|
||
describe('initiator', () => { | ||
const server = http.createServer((req, res) => { | ||
res.end(req.headers['sec-purpose']) | ||
}) | ||
|
||
before(async () => { | ||
server.listen(0) | ||
await events.once(server, 'listening') | ||
}) | ||
|
||
after(closeServerAsPromise(server)) | ||
|
||
test('if initiator is not "prefetch" then sec-purpose is not set', async (t) => { | ||
const url = `http://localhost:${server.address().port}` | ||
|
||
const response = await fetch(url, { | ||
initiator: '' | ||
}) | ||
|
||
assert.strictEqual(await response.text(), '') | ||
}) | ||
|
||
test('if initiator is set to prefetch then the sec-purpose header is set to "prefetch"', async (t) => { | ||
const url = `http://localhost:${server.address().port}` | ||
|
||
const response = await fetch(new Request(url, { | ||
initiator: 'prefetch' | ||
})) | ||
|
||
assert.deepStrictEqual(await response.text(), 'prefetch') | ||
}) | ||
}) |
Uh oh!
There was an error while loading. Please reload this page.