@whatwg-node/node-fetch 0.7.8-alpha-20250122230954-3105b2fac861fe650311d5dc0f4a88470234b0b5 → 0.7.8-alpha-20250124174946-bf76ab63fc7e7c5ee6898f3bf12f95ef0ac79a63

Sign up to get free protection for your applications and to get access to all the features.
package/esm/fetchCurl.js CHANGED
@@ -3,157 +3,155 @@ import { pipeline } from 'node:stream/promises';
3
3
  import { rootCertificates } from 'node:tls';
4
4
  import { PonyfillResponse } from './Response.js';
5
5
  import { createDeferredPromise, defaultHeadersSerializer, isNodeReadable } from './utils.js';
6
- export function createFetchCurl(nodeLibcurl) {
7
- return function fetchCurl(fetchRequest) {
8
- const { Curl, CurlFeature, CurlPause, CurlProgressFunc } = nodeLibcurl;
9
- const curlHandle = new Curl();
10
- curlHandle.enable(CurlFeature.NoDataParsing);
11
- curlHandle.setOpt('URL', fetchRequest.url);
12
- if (process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0') {
13
- curlHandle.setOpt('SSL_VERIFYPEER', false);
6
+ export function fetchCurl(fetchRequest) {
7
+ const { Curl, CurlFeature, CurlPause, CurlProgressFunc } = globalThis['libcurl'];
8
+ const curlHandle = new Curl();
9
+ curlHandle.enable(CurlFeature.NoDataParsing);
10
+ curlHandle.setOpt('URL', fetchRequest.url);
11
+ if (process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0') {
12
+ curlHandle.setOpt('SSL_VERIFYPEER', false);
13
+ }
14
+ if (process.env.NODE_EXTRA_CA_CERTS) {
15
+ curlHandle.setOpt('CAINFO', process.env.NODE_EXTRA_CA_CERTS);
16
+ }
17
+ else {
18
+ curlHandle.setOpt('CAINFO_BLOB', rootCertificates.join('\n'));
19
+ }
20
+ curlHandle.enable(CurlFeature.StreamResponse);
21
+ curlHandle.setStreamProgressCallback(function () {
22
+ return fetchRequest['_signal']?.aborted
23
+ ? process.env.DEBUG
24
+ ? CurlProgressFunc.Continue
25
+ : 1
26
+ : 0;
27
+ });
28
+ if (fetchRequest['bodyType'] === 'String') {
29
+ curlHandle.setOpt('POSTFIELDS', fetchRequest['bodyInit']);
30
+ }
31
+ else {
32
+ const nodeReadable = (fetchRequest.body != null
33
+ ? isNodeReadable(fetchRequest.body)
34
+ ? fetchRequest.body
35
+ : Readable.from(fetchRequest.body)
36
+ : null);
37
+ if (nodeReadable) {
38
+ curlHandle.setOpt('UPLOAD', true);
39
+ curlHandle.setUploadStream(nodeReadable);
14
40
  }
15
- if (process.env.NODE_EXTRA_CA_CERTS) {
16
- curlHandle.setOpt('CAINFO', process.env.NODE_EXTRA_CA_CERTS);
17
- }
18
- else {
19
- curlHandle.setOpt('CAINFO_BLOB', rootCertificates.join('\n'));
41
+ }
42
+ if (process.env.DEBUG) {
43
+ curlHandle.setOpt('VERBOSE', true);
44
+ }
45
+ curlHandle.setOpt('TRANSFER_ENCODING', false);
46
+ curlHandle.setOpt('HTTP_TRANSFER_DECODING', true);
47
+ curlHandle.setOpt('FOLLOWLOCATION', fetchRequest.redirect === 'follow');
48
+ curlHandle.setOpt('MAXREDIRS', 20);
49
+ curlHandle.setOpt('ACCEPT_ENCODING', '');
50
+ curlHandle.setOpt('CUSTOMREQUEST', fetchRequest.method);
51
+ const headersSerializer = fetchRequest.headersSerializer || defaultHeadersSerializer;
52
+ let size;
53
+ const curlHeaders = headersSerializer(fetchRequest.headers, value => {
54
+ size = Number(value);
55
+ });
56
+ if (size != null) {
57
+ curlHandle.setOpt('INFILESIZE', size);
58
+ }
59
+ curlHandle.setOpt('HTTPHEADER', curlHeaders);
60
+ curlHandle.enable(CurlFeature.NoHeaderParsing);
61
+ const deferredPromise = createDeferredPromise();
62
+ let streamResolved;
63
+ function onAbort() {
64
+ if (curlHandle.isOpen) {
65
+ try {
66
+ curlHandle.pause(CurlPause.Recv);
67
+ }
68
+ catch (e) {
69
+ deferredPromise.reject(e);
70
+ }
20
71
  }
21
- curlHandle.enable(CurlFeature.StreamResponse);
22
- curlHandle.setStreamProgressCallback(function () {
23
- return fetchRequest['_signal']?.aborted
24
- ? process.env.DEBUG
25
- ? CurlProgressFunc.Continue
26
- : 1
27
- : 0;
28
- });
29
- if (fetchRequest['bodyType'] === 'String') {
30
- curlHandle.setOpt('POSTFIELDS', fetchRequest['bodyInit']);
72
+ }
73
+ if (fetchRequest['_signal']) {
74
+ fetchRequest['_signal'].addEventListener('abort', onAbort, { once: true });
75
+ }
76
+ curlHandle.once('end', function endListener() {
77
+ try {
78
+ curlHandle.close();
31
79
  }
32
- else {
33
- const nodeReadable = (fetchRequest.body != null
34
- ? isNodeReadable(fetchRequest.body)
35
- ? fetchRequest.body
36
- : Readable.from(fetchRequest.body)
37
- : null);
38
- if (nodeReadable) {
39
- curlHandle.setOpt('UPLOAD', true);
40
- curlHandle.setUploadStream(nodeReadable);
41
- }
80
+ catch (e) {
81
+ deferredPromise.reject(e);
42
82
  }
43
- if (process.env.DEBUG) {
44
- curlHandle.setOpt('VERBOSE', true);
83
+ if (fetchRequest['_signal']) {
84
+ fetchRequest['_signal'].removeEventListener('abort', onAbort);
45
85
  }
46
- curlHandle.setOpt('TRANSFER_ENCODING', false);
47
- curlHandle.setOpt('HTTP_TRANSFER_DECODING', true);
48
- curlHandle.setOpt('FOLLOWLOCATION', fetchRequest.redirect === 'follow');
49
- curlHandle.setOpt('MAXREDIRS', 20);
50
- curlHandle.setOpt('ACCEPT_ENCODING', '');
51
- curlHandle.setOpt('CUSTOMREQUEST', fetchRequest.method);
52
- const headersSerializer = fetchRequest.headersSerializer || defaultHeadersSerializer;
53
- let size;
54
- const curlHeaders = headersSerializer(fetchRequest.headers, value => {
55
- size = Number(value);
56
- });
57
- if (size != null) {
58
- curlHandle.setOpt('INFILESIZE', size);
86
+ });
87
+ curlHandle.once('error', function errorListener(error) {
88
+ if (streamResolved && !streamResolved.closed && !streamResolved.destroyed) {
89
+ streamResolved.destroy(error);
59
90
  }
60
- curlHandle.setOpt('HTTPHEADER', curlHeaders);
61
- curlHandle.enable(CurlFeature.NoHeaderParsing);
62
- const deferredPromise = createDeferredPromise();
63
- let streamResolved;
64
- function onAbort() {
65
- if (curlHandle.isOpen) {
66
- try {
67
- curlHandle.pause(CurlPause.Recv);
68
- }
69
- catch (e) {
70
- deferredPromise.reject(e);
71
- }
91
+ else {
92
+ if (error.message === 'Operation was aborted by an application callback') {
93
+ error.message = 'The operation was aborted.';
72
94
  }
95
+ deferredPromise.reject(error);
73
96
  }
74
- if (fetchRequest['_signal']) {
75
- fetchRequest['_signal'].addEventListener('abort', onAbort, { once: true });
97
+ try {
98
+ curlHandle.close();
76
99
  }
77
- curlHandle.once('end', function endListener() {
78
- try {
79
- curlHandle.close();
80
- }
81
- catch (e) {
82
- deferredPromise.reject(e);
83
- }
84
- if (fetchRequest['_signal']) {
85
- fetchRequest['_signal'].removeEventListener('abort', onAbort);
86
- }
87
- });
88
- curlHandle.once('error', function errorListener(error) {
89
- if (streamResolved && !streamResolved.closed && !streamResolved.destroyed) {
90
- streamResolved.destroy(error);
100
+ catch (e) {
101
+ deferredPromise.reject(e);
102
+ }
103
+ });
104
+ curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
105
+ const outputStream = new PassThrough();
106
+ pipeline(stream, outputStream, {
107
+ end: true,
108
+ signal: fetchRequest['_signal'] ?? undefined,
109
+ })
110
+ .then(() => {
111
+ if (!stream.destroyed) {
112
+ stream.resume();
91
113
  }
92
- else {
93
- if (error.message === 'Operation was aborted by an application callback') {
94
- error.message = 'The operation was aborted.';
114
+ })
115
+ .catch(deferredPromise.reject);
116
+ const headersFlat = headersBuf
117
+ .toString('utf8')
118
+ .split(/\r?\n|\r/g)
119
+ .filter(headerFilter => {
120
+ if (headerFilter && !headerFilter.startsWith('HTTP/')) {
121
+ if (fetchRequest.redirect === 'error' &&
122
+ (headerFilter.includes('location') || headerFilter.includes('Location'))) {
123
+ if (!stream.destroyed) {
124
+ stream.resume();
125
+ }
126
+ outputStream.destroy();
127
+ deferredPromise.reject(new Error('redirect is not allowed'));
95
128
  }
96
- deferredPromise.reject(error);
97
- }
98
- try {
99
- curlHandle.close();
100
- }
101
- catch (e) {
102
- deferredPromise.reject(e);
129
+ return true;
103
130
  }
131
+ return false;
104
132
  });
105
- curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
106
- const outputStream = new PassThrough();
107
- pipeline(stream, outputStream, {
108
- end: true,
109
- signal: fetchRequest['_signal'] ?? undefined,
110
- })
111
- .then(() => {
112
- if (!stream.destroyed) {
113
- stream.resume();
114
- }
115
- })
116
- .catch(deferredPromise.reject);
117
- const headersFlat = headersBuf
118
- .toString('utf8')
119
- .split(/\r?\n|\r/g)
120
- .filter(headerFilter => {
121
- if (headerFilter && !headerFilter.startsWith('HTTP/')) {
122
- if (fetchRequest.redirect === 'error' &&
123
- (headerFilter.includes('location') || headerFilter.includes('Location'))) {
124
- if (!stream.destroyed) {
125
- stream.resume();
126
- }
127
- outputStream.destroy();
128
- deferredPromise.reject(new Error('redirect is not allowed'));
129
- }
130
- return true;
131
- }
132
- return false;
133
- });
134
- const headersInit = headersFlat.map(headerFlat => headerFlat.split(/:\s(.+)/).slice(0, 2));
135
- const ponyfillResponse = new PonyfillResponse(outputStream, {
136
- status,
137
- headers: headersInit,
138
- url: curlHandle.getInfo(Curl.info.REDIRECT_URL)?.toString() || fetchRequest.url,
139
- redirected: Number(curlHandle.getInfo(Curl.info.REDIRECT_COUNT)) > 0,
140
- });
141
- deferredPromise.resolve(ponyfillResponse);
142
- streamResolved = outputStream;
133
+ const headersInit = headersFlat.map(headerFlat => headerFlat.split(/:\s(.+)/).slice(0, 2));
134
+ const ponyfillResponse = new PonyfillResponse(outputStream, {
135
+ status,
136
+ headers: headersInit,
137
+ url: curlHandle.getInfo(Curl.info.REDIRECT_URL)?.toString() || fetchRequest.url,
138
+ redirected: Number(curlHandle.getInfo(Curl.info.REDIRECT_COUNT)) > 0,
143
139
  });
144
- let count = 0;
145
- try {
146
- count = Curl.getCount();
147
- }
148
- catch { }
149
- if (count > 0) {
150
- setImmediate(() => {
151
- curlHandle.perform();
152
- });
153
- }
154
- else {
140
+ deferredPromise.resolve(ponyfillResponse);
141
+ streamResolved = outputStream;
142
+ });
143
+ let count = 0;
144
+ try {
145
+ count = Curl.getCount();
146
+ }
147
+ catch { }
148
+ if (count > 0) {
149
+ setImmediate(() => {
155
150
  curlHandle.perform();
156
- }
157
- return deferredPromise.promise;
158
- };
151
+ });
152
+ }
153
+ else {
154
+ curlHandle.perform();
155
+ }
156
+ return deferredPromise.promise;
159
157
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.7.8-alpha-20250122230954-3105b2fac861fe650311d5dc0f4a88470234b0b5",
3
+ "version": "0.7.8-alpha-20250124174946-bf76ab63fc7e7c5ee6898f3bf12f95ef0ac79a63",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -31,7 +31,6 @@ export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> im
31
31
  get parsedUrl(): URL;
32
32
  duplex: 'half' | 'full';
33
33
  agent: HTTPAgent | HTTPSAgent | false | undefined;
34
- dispatcher: import('undici').Dispatcher | undefined;
35
34
  private _signal;
36
35
  get signal(): AbortSignal;
37
36
  clone(): PonyfillRequest<TJSON>;
@@ -31,7 +31,6 @@ export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> im
31
31
  get parsedUrl(): URL;
32
32
  duplex: 'half' | 'full';
33
33
  agent: HTTPAgent | HTTPSAgent | false | undefined;
34
- dispatcher: import('undici').Dispatcher | undefined;
35
34
  private _signal;
36
35
  get signal(): AbortSignal;
37
36
  clone(): PonyfillRequest<TJSON>;
@@ -1,5 +1,3 @@
1
- import { fetchNodeHttp } from './fetchNodeHttp.cjs';
2
1
  import { PonyfillRequest, RequestPonyfillInit } from './Request.cjs';
3
2
  import { PonyfillResponse } from './Response.cjs';
4
- export declare function createFetchPonyfill(fetchFn: typeof fetchNodeHttp): <TResponseJSON = any, TRequestJSON = any>(info: string | PonyfillRequest<TRequestJSON> | URL, init?: RequestPonyfillInit) => Promise<PonyfillResponse<TResponseJSON>>;
5
3
  export declare function fetchPonyfill<TResponseJSON = any, TRequestJSON = any>(info: string | PonyfillRequest<TRequestJSON> | URL, init?: RequestPonyfillInit): Promise<PonyfillResponse<TResponseJSON>>;
@@ -1,5 +1,3 @@
1
- import { fetchNodeHttp } from './fetchNodeHttp.js';
2
1
  import { PonyfillRequest, RequestPonyfillInit } from './Request.js';
3
2
  import { PonyfillResponse } from './Response.js';
4
- export declare function createFetchPonyfill(fetchFn: typeof fetchNodeHttp): <TResponseJSON = any, TRequestJSON = any>(info: string | PonyfillRequest<TRequestJSON> | URL, init?: RequestPonyfillInit) => Promise<PonyfillResponse<TResponseJSON>>;
5
3
  export declare function fetchPonyfill<TResponseJSON = any, TRequestJSON = any>(info: string | PonyfillRequest<TRequestJSON> | URL, init?: RequestPonyfillInit): Promise<PonyfillResponse<TResponseJSON>>;
@@ -1,3 +1,3 @@
1
1
  import { PonyfillRequest } from './Request.cjs';
2
2
  import { PonyfillResponse } from './Response.cjs';
3
- export declare function createFetchCurl(nodeLibcurl: typeof import('node-libcurl')): <TResponseJSON = any, TRequestJSON = any>(fetchRequest: PonyfillRequest<TRequestJSON>) => Promise<PonyfillResponse<TResponseJSON>>;
3
+ export declare function fetchCurl<TResponseJSON = any, TRequestJSON = any>(fetchRequest: PonyfillRequest<TRequestJSON>): Promise<PonyfillResponse<TResponseJSON>>;
@@ -1,3 +1,3 @@
1
1
  import { PonyfillRequest } from './Request.js';
2
2
  import { PonyfillResponse } from './Response.js';
3
- export declare function createFetchCurl(nodeLibcurl: typeof import('node-libcurl')): <TResponseJSON = any, TRequestJSON = any>(fetchRequest: PonyfillRequest<TRequestJSON>) => Promise<PonyfillResponse<TResponseJSON>>;
3
+ export declare function fetchCurl<TResponseJSON = any, TRequestJSON = any>(fetchRequest: PonyfillRequest<TRequestJSON>): Promise<PonyfillResponse<TResponseJSON>>;
@@ -6,7 +6,7 @@ export declare function isArrayBufferView(obj: any): obj is ArrayBufferView;
6
6
  export declare function isNodeReadable(obj: any): obj is Readable;
7
7
  export interface DeferredPromise<T = void> {
8
8
  promise: Promise<T>;
9
- resolve: (value: T | PromiseLike<T>) => void;
9
+ resolve: (value: T) => void;
10
10
  reject: (reason: any) => void;
11
11
  }
12
12
  export declare function createDeferredPromise<T = void>(): DeferredPromise<T>;
@@ -6,7 +6,7 @@ export declare function isArrayBufferView(obj: any): obj is ArrayBufferView;
6
6
  export declare function isNodeReadable(obj: any): obj is Readable;
7
7
  export interface DeferredPromise<T = void> {
8
8
  promise: Promise<T>;
9
- resolve: (value: T | PromiseLike<T>) => void;
9
+ resolve: (value: T) => void;
10
10
  reject: (reason: any) => void;
11
11
  }
12
12
  export declare function createDeferredPromise<T = void>(): DeferredPromise<T>;
@@ -1,190 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createFetchUndici = createFetchUndici;
4
- const node_stream_1 = require("node:stream");
5
- const types_1 = require("node:util/types");
6
- const node_zlib_1 = require("node:zlib");
7
- const fetchNodeHttp_js_1 = require("./fetchNodeHttp.js");
8
- const Request_js_1 = require("./Request.js");
9
- const Response_js_1 = require("./Response.js");
10
- const URL_js_1 = require("./URL.js");
11
- const utils_js_1 = require("./utils.js");
12
- function createFetchUndici(getGlobalDispatcher) {
13
- return function fetchUndici(fetchRequest) {
14
- const dispatcher = fetchRequest.dispatcher || getGlobalDispatcher();
15
- if (!dispatcher) {
16
- if (process.env.DEBUG) {
17
- console.debug('[@whatwg-node/node-fetch] - native undici dispatcher not available, falling back to node:http');
18
- }
19
- return (0, fetchNodeHttp_js_1.fetchNodeHttp)(fetchRequest);
20
- }
21
- const deferred = (0, utils_js_1.createDeferredPromise)();
22
- let abortListener;
23
- let passthrough;
24
- let response;
25
- let body = null;
26
- const bodyInit = fetchRequest['bodyInit'];
27
- if (bodyInit != null) {
28
- if (typeof bodyInit === 'string' ||
29
- Buffer.isBuffer(bodyInit) ||
30
- (0, types_1.isUint8Array)(bodyInit) ||
31
- bodyInit instanceof node_stream_1.Readable) {
32
- body = bodyInit;
33
- }
34
- else if (fetchRequest.body != null) {
35
- if ((0, utils_js_1.isNodeReadable)(fetchRequest.body?.readable)) {
36
- body = fetchRequest.body.readable;
37
- }
38
- else {
39
- body = node_stream_1.Readable.from(fetchRequest.body);
40
- }
41
- }
42
- }
43
- function setPassthrough(contentEncoding) {
44
- switch (contentEncoding) {
45
- case 'x-gzip':
46
- case 'gzip':
47
- passthrough = (0, node_zlib_1.createGunzip)();
48
- break;
49
- case 'x-deflate':
50
- case 'deflate':
51
- passthrough = (0, node_zlib_1.createInflate)();
52
- break;
53
- case 'x-deflate-raw':
54
- case 'deflate-raw':
55
- passthrough = (0, node_zlib_1.createInflateRaw)();
56
- break;
57
- case 'br':
58
- passthrough = (0, node_zlib_1.createBrotliDecompress)();
59
- break;
60
- default:
61
- passthrough = new node_stream_1.PassThrough();
62
- }
63
- return passthrough;
64
- }
65
- function onAbort(e) {
66
- fetchRequest['_signal']?.removeEventListener('abort', abortListener);
67
- passthrough?.destroy(e);
68
- deferred.reject(e);
69
- }
70
- const headersSerializer = fetchRequest.headersSerializer || utils_js_1.getHeadersObj;
71
- const nodeHeaders = headersSerializer(fetchRequest.headers);
72
- if (nodeHeaders['accept-encoding'] == null) {
73
- nodeHeaders['accept-encoding'] = 'gzip, deflate, br';
74
- }
75
- const dispatcherReturn = dispatcher.dispatch({
76
- origin: fetchRequest.parsedUrl.origin,
77
- path: fetchRequest.parsedUrl.pathname,
78
- query: Object.fromEntries(fetchRequest.parsedUrl.searchParams),
79
- method: fetchRequest.method,
80
- headers: nodeHeaders,
81
- body,
82
- }, {
83
- onRequestStart(controller) {
84
- abortListener = function abortListener() {
85
- onAbort(fetchRequest['_signal']?.reason);
86
- controller.abort(fetchRequest['_signal']?.reason);
87
- };
88
- fetchRequest['_signal']?.addEventListener('abort', abortListener, { once: true });
89
- },
90
- onRequestUpgrade(_controller, statusCode, headers, socket) {
91
- response = new Response_js_1.PonyfillResponse(socket, {
92
- status: statusCode,
93
- headers: headers,
94
- url: fetchRequest.url,
95
- });
96
- deferred.resolve(response);
97
- fetchRequest['_signal']?.removeEventListener('abort', abortListener);
98
- },
99
- onResponseStart(controller, statusCode, headers, statusMessage) {
100
- if (headers.location) {
101
- if (fetchRequest.redirect === 'error') {
102
- const redirectError = new Error('Redirects are not allowed');
103
- deferred.reject(redirectError);
104
- controller.resume();
105
- return;
106
- }
107
- if (fetchRequest.redirect === 'follow') {
108
- const redirectedUrl = new URL_js_1.PonyfillURL(headers.location, fetchRequest.parsedUrl || fetchRequest.url);
109
- const redirectResponse$ = fetchUndici(new Request_js_1.PonyfillRequest(redirectedUrl, fetchRequest));
110
- deferred.resolve(redirectResponse$.then(redirectResponse => {
111
- redirectResponse.redirected = true;
112
- return redirectResponse;
113
- }));
114
- controller.resume();
115
- return;
116
- }
117
- }
118
- passthrough = setPassthrough(headers['content-encoding']);
119
- deferred.resolve(new Response_js_1.PonyfillResponse(passthrough, {
120
- status: statusCode,
121
- statusText: statusMessage,
122
- headers: headers,
123
- url: fetchRequest.url,
124
- }));
125
- },
126
- onResponseData(controller, chunk) {
127
- passthrough.write(chunk);
128
- if (controller.reason) {
129
- onAbort(controller.reason);
130
- }
131
- },
132
- onResponseEnd(controller, _trailers) {
133
- if (controller.reason) {
134
- onAbort(controller.reason);
135
- }
136
- else {
137
- passthrough.end();
138
- fetchRequest['_signal']?.removeEventListener('abort', abortListener);
139
- }
140
- },
141
- onResponseError(controller, error) {
142
- onAbort(error || controller.reason);
143
- },
144
- // Old Undici support
145
- onConnect(abort) {
146
- abortListener = function abortListener() {
147
- abort(fetchRequest['_signal']?.reason);
148
- onAbort(fetchRequest['_signal']?.reason);
149
- };
150
- fetchRequest['_signal']?.addEventListener('abort', abortListener, { once: true });
151
- },
152
- onError(error) {
153
- onAbort(error);
154
- },
155
- // TODO: onUpgrade
156
- onHeaders(statusCode, headersBuf, _resume, statusText) {
157
- const headers = headersBuf.map(headerBuf => {
158
- const header = headerBuf
159
- .toString('utf-8')
160
- .split(/:\s(.+)/)
161
- .slice(0, 2);
162
- if (header[0] === 'content-encoding') {
163
- const contentEncoding = header[1];
164
- setPassthrough(contentEncoding);
165
- }
166
- return header;
167
- });
168
- passthrough ||= new node_stream_1.PassThrough();
169
- deferred.resolve(new Response_js_1.PonyfillResponse(passthrough, {
170
- status: statusCode,
171
- statusText,
172
- headers,
173
- url: fetchRequest.url,
174
- }));
175
- return true;
176
- },
177
- onData(chunk) {
178
- return passthrough.write(chunk);
179
- },
180
- onComplete() {
181
- passthrough.end();
182
- fetchRequest['_signal']?.removeEventListener('abort', abortListener);
183
- },
184
- });
185
- if (!dispatcherReturn) {
186
- console.warn('Undici dispatcher returned false');
187
- }
188
- return deferred.promise;
189
- };
190
- }