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

fix: support cloudflare workers #559

Merged
merged 3 commits into from
Feb 25, 2024
Merged
Changes from 2 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: 2 additions & 1 deletion source/core/Ky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ export class Ky {
// eslint-disable-next-line complexity
constructor(input: Input, options: Options = {}) {
this._input = input;
const isCredentialsSupported = 'credentials' in Request.prototype;
this._options = {
// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
credentials: (this._input as Request).credentials || 'same-origin',
credentials: isCredentialsSupported ? ((this._input as Request).credentials || 'same-origin') : 'same-origin',
Copy link

@fregante fregante Feb 24, 2024

Choose a reason for hiding this comment

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

I don’t think this is gonna work, _options.credentials should not be set at all, according to the error.

Also the comment is very outdated and we can probably use:

Suggested change
credentials: isCredentialsSupported ? ((this._input as Request).credentials || 'same-origin') : 'same-origin',
credentials: isCredentialsSupported ? (this._input as Request).credentials : undefined,

… as long as CloudFlare accepts {credentials: undefined} and doesn't actually require {}

by the way this would fix two duplicates:

...options,
headers: mergeHeaders((this._input as Request).headers, options.headers),
hooks: deepMerge<Required<Hooks>>(
Expand Down