Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ export function Request(input, options) {
this.mode = options.mode || this.mode || null
this.signal = options.signal || this.signal
this.referrer = null
this.cf = options.cf || {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to be stricter about what is possible on the cf object otherwise the behaviour doesn't align with the Cloudflare implementation. My proposal here is that we drop any keys that are not defined in the controlling Cloudflare feature docs to ensure that if a key is set, it will remove it and cannot be asserted against. Without this, someone could any key to this object, test against it but not have it do anything within the worker environment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1


if ((this.method === 'GET' || this.method === 'HEAD') && body) {
throw new TypeError('Body not allowed for GET or HEAD requests')
Expand Down
5 changes: 5 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ exercise.forEach(function(exerciseMode) {
})
})

test('construct with Cloudflare Request Attribute', function() {
var request = new Request('https://fetch.spec.whatwg.org/', {cf: {country: 'AUS'}})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: country code should be AU.

assert.equal(request.cf, {country: 'AUS'})
})

featureDependent(test, !nativeChrome, 'construct with used Request body', function() {
var request1 = new Request('https://fetch.spec.whatwg.org/', {
method: 'post',
Expand Down