@whatwg-node/node-fetch 0.8.3 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,7 +26,7 @@ function fetchNodeHttp(fetchRequest) {
26
26
  const requestFn = getRequestFnForProtocol(fetchRequest.parsedUrl?.protocol || fetchRequest.url);
27
27
  const headersSerializer = fetchRequest.headersSerializer || utils_js_1.getHeadersObj;
28
28
  const nodeHeaders = headersSerializer(fetchRequest.headers);
29
- nodeHeaders['accept-encoding'] ||= 'gzip, deflate, br';
29
+ nodeHeaders['accept-encoding'] ||= utils_js_1.DEFAULT_ACCEPT_ENCODING;
30
30
  if (nodeHeaders['user-agent'] == null && nodeHeaders['User-Agent'] == null) {
31
31
  nodeHeaders['user-agent'] = 'node';
32
32
  }
@@ -76,7 +76,9 @@ function fetchNodeHttp(fetchRequest) {
76
76
  outputStream = node_zlib_1.default.createBrotliDecompress();
77
77
  break;
78
78
  case 'zstd':
79
- outputStream = node_zlib_1.default.createZstdDecompress();
79
+ if (node_zlib_1.default.createZstdDecompress != null) {
80
+ outputStream = node_zlib_1.default.createZstdDecompress();
81
+ }
80
82
  break;
81
83
  }
82
84
  if (nodeResponse.headers.location && (0, utils_js_1.shouldRedirect)(nodeResponse.statusCode)) {
package/cjs/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fakePromise = void 0;
3
+ exports.DEFAULT_ACCEPT_ENCODING = exports.fakePromise = void 0;
4
4
  exports.getHeadersObj = getHeadersObj;
5
5
  exports.defaultHeadersSerializer = defaultHeadersSerializer;
6
6
  exports.isArrayBufferView = isArrayBufferView;
@@ -112,6 +112,7 @@ class AbortError extends Error {
112
112
  this.name = 'AbortError';
113
113
  }
114
114
  }
115
+ exports.DEFAULT_ACCEPT_ENCODING = getSupportedFormats().join(', ');
115
116
  function getSupportedFormats() {
116
117
  const baseFormats = ['gzip', 'deflate', 'br'];
117
118
  if (!globalThis.process?.versions?.node?.startsWith('2')) {
@@ -6,7 +6,7 @@ import { handleMaybePromise } from '@whatwg-node/promise-helpers';
6
6
  import { PonyfillRequest } from './Request.js';
7
7
  import { PonyfillResponse } from './Response.js';
8
8
  import { PonyfillURL } from './URL.js';
9
- import { endStream, getHeadersObj, isNodeReadable, pipeThrough, safeWrite, shouldRedirect, } from './utils.js';
9
+ import { DEFAULT_ACCEPT_ENCODING, endStream, getHeadersObj, isNodeReadable, pipeThrough, safeWrite, shouldRedirect, } from './utils.js';
10
10
  function getRequestFnForProtocol(url) {
11
11
  if (url.startsWith('http:')) {
12
12
  return httpRequest;
@@ -22,7 +22,7 @@ export function fetchNodeHttp(fetchRequest) {
22
22
  const requestFn = getRequestFnForProtocol(fetchRequest.parsedUrl?.protocol || fetchRequest.url);
23
23
  const headersSerializer = fetchRequest.headersSerializer || getHeadersObj;
24
24
  const nodeHeaders = headersSerializer(fetchRequest.headers);
25
- nodeHeaders['accept-encoding'] ||= 'gzip, deflate, br';
25
+ nodeHeaders['accept-encoding'] ||= DEFAULT_ACCEPT_ENCODING;
26
26
  if (nodeHeaders['user-agent'] == null && nodeHeaders['User-Agent'] == null) {
27
27
  nodeHeaders['user-agent'] = 'node';
28
28
  }
@@ -72,7 +72,9 @@ export function fetchNodeHttp(fetchRequest) {
72
72
  outputStream = zlib.createBrotliDecompress();
73
73
  break;
74
74
  case 'zstd':
75
- outputStream = zlib.createZstdDecompress();
75
+ if (zlib.createZstdDecompress != null) {
76
+ outputStream = zlib.createZstdDecompress();
77
+ }
76
78
  break;
77
79
  }
78
80
  if (nodeResponse.headers.location && shouldRedirect(nodeResponse.statusCode)) {
package/esm/utils.js CHANGED
@@ -97,6 +97,7 @@ class AbortError extends Error {
97
97
  this.name = 'AbortError';
98
98
  }
99
99
  }
100
+ export const DEFAULT_ACCEPT_ENCODING = getSupportedFormats().join(', ');
100
101
  export function getSupportedFormats() {
101
102
  const baseFormats = ['gzip', 'deflate', 'br'];
102
103
  if (!globalThis.process?.versions?.node?.startsWith('2')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -17,4 +17,5 @@ export declare function endStream(stream: {
17
17
  end: () => void;
18
18
  }): void;
19
19
  export declare function safeWrite(chunk: any, stream: Writable): Promise<any[]> | undefined;
20
+ export declare const DEFAULT_ACCEPT_ENCODING: string;
20
21
  export declare function getSupportedFormats(): PonyfillCompressionFormat[];
@@ -17,4 +17,5 @@ export declare function endStream(stream: {
17
17
  end: () => void;
18
18
  }): void;
19
19
  export declare function safeWrite(chunk: any, stream: Writable): Promise<any[]> | undefined;
20
+ export declare const DEFAULT_ACCEPT_ENCODING: string;
20
21
  export declare function getSupportedFormats(): PonyfillCompressionFormat[];