Skip to content

Commit bccbfdb

Browse files
committedOct 12, 2022
Fix Firefox compatibility for the onDownloadProgress option
Fixes #455
1 parent da40323 commit bccbfdb

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed
 

‎source/core/Ky.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ import {deepMerge, mergeHeaders} from '../utils/merge.js';
77
import {normalizeRequestMethod, normalizeRetryOptions} from '../utils/normalize.js';
88
import {delay, timeout, TimeoutOptions} from '../utils/time.js';
99
import {ObjectEntries} from '../utils/types.js';
10-
import {maxSafeTimeout, responseTypes, stop, supportsAbortController, supportsFormData, supportsStreams} from './constants.js';
10+
import {
11+
maxSafeTimeout,
12+
responseTypes,
13+
stop,
14+
supportsAbortController,
15+
supportsFormData,
16+
supportsResponseStreams,
17+
supportsRequestStreams,
18+
} from './constants.js';
1119

1220
export class Ky {
1321
// eslint-disable-next-line @typescript-eslint/promise-function-async
@@ -56,7 +64,7 @@ export class Ky {
5664
throw new TypeError('The `onDownloadProgress` option must be a function');
5765
}
5866

59-
if (!supportsStreams) {
67+
if (!supportsResponseStreams) {
6068
throw new Error('Streams are not supported in your environment. `ReadableStream` is missing.');
6169
}
6270

@@ -155,7 +163,7 @@ export class Ky {
155163

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

158-
if (supportsStreams) {
166+
if (supportsRequestStreams) {
159167
// @ts-expect-error - Types are outdated.
160168
this.request.duplex = 'half';
161169
}

‎source/core/constants.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {Expect, Equal} from '@type-challenges/utils';
22
import {HttpMethod} from '../types/options.js';
33

4-
export const supportsStreams = (() => {
4+
export const supportsRequestStreams = (() => {
55
let duplexAccessed = false;
66
let hasContentType = false;
77
const supportsReadableStream = typeof globalThis.ReadableStream === 'function';
@@ -22,6 +22,7 @@ export const supportsStreams = (() => {
2222
})();
2323

2424
export const supportsAbortController = typeof globalThis.AbortController === 'function';
25+
export const supportsResponseStreams = typeof globalThis.ReadableStream === 'function';
2526
export const supportsFormData = typeof globalThis.FormData === 'function';
2627

2728
export const requestMethods = ['get', 'post', 'put', 'patch', 'head', 'delete'] as const;

0 commit comments

Comments
 (0)
Please sign in to comment.