Skip to content

Commit

Permalink
Fix compatibility with Unidici
Browse files Browse the repository at this point in the history
Fixes #467
  • Loading branch information
sindresorhus committed Dec 29, 2022
1 parent aaec57a commit ae2fe07
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions source/core/Ky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ export class Ky {
this._options.signal = this.abortController.signal;
}

this.request = new globalThis.Request(this._input as RequestInfo, this._options as RequestInit);

if (supportsRequestStreams) {
// @ts-expect-error - Types are outdated.
this.request.duplex = 'half';
this._options.duplex = 'half';
}

this.request = new globalThis.Request(this._input as RequestInfo, this._options as RequestInit);

if (this._options.searchParams) {
// eslint-disable-next-line unicorn/prevent-abbreviations
const textSearchParams = typeof this._options.searchParams === 'string'
Expand All @@ -194,7 +194,8 @@ export class Ky {
this.request.headers.delete('content-type');
}

this.request = new globalThis.Request(new globalThis.Request(url, this.request), this._options as RequestInit);
// The spread of `this.request` is required as otherwise it misses the `duplex` option for some reason and throws.
this.request = new globalThis.Request(new globalThis.Request(url, {...this.request}), this._options as RequestInit);
}

if (this._options.json !== undefined) {
Expand Down

0 comments on commit ae2fe07

Please sign in to comment.