@whatwg-node/node-fetch 0.7.3 → 0.7.4-alpha-20241125125556-f6d4dd923d74499ecd7ef790e4704bf3bffd1892
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.
- package/cjs/IteratorObject.js +3 -4
- package/cjs/ReadableStream.js +28 -26
- package/cjs/Request.js +43 -8
- package/cjs/URL.js +1 -0
- package/cjs/fetchNodeHttp.js +23 -7
- package/cjs/utils.js +1 -5
- package/esm/IteratorObject.js +3 -4
- package/esm/ReadableStream.js +28 -26
- package/esm/Request.js +43 -8
- package/esm/URL.js +1 -0
- package/esm/fetchNodeHttp.js +23 -7
- package/esm/utils.js +1 -5
- package/package.json +2 -1
- package/typings/IteratorObject.d.cts +2 -1
- package/typings/IteratorObject.d.ts +2 -1
- package/typings/ReadableStream.d.cts +1 -0
- package/typings/ReadableStream.d.ts +1 -0
- package/typings/Request.d.cts +4 -1
- package/typings/Request.d.ts +4 -1
- package/typings/URL.d.cts +1 -0
- package/typings/URL.d.ts +1 -0
package/cjs/IteratorObject.js
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.PonyfillIteratorObject = void 0;
|
4
4
|
const node_util_1 = require("node:util");
|
5
|
+
const disposablestack_1 = require("@whatwg-node/disposablestack");
|
5
6
|
const utils_js_1 = require("./utils.js");
|
6
7
|
class PonyfillIteratorObject {
|
7
8
|
iterableIterator;
|
@@ -110,10 +111,8 @@ class PonyfillIteratorObject {
|
|
110
111
|
toArray() {
|
111
112
|
return Array.from(this.iterableIterator);
|
112
113
|
}
|
113
|
-
[
|
114
|
-
|
115
|
-
this.iterableIterator.return();
|
116
|
-
}
|
114
|
+
[disposablestack_1.DisposableSymbols.dispose]() {
|
115
|
+
this.iterableIterator.return?.();
|
117
116
|
}
|
118
117
|
next(...[value]) {
|
119
118
|
return this.iterableIterator.next(value);
|
package/cjs/ReadableStream.js
CHANGED
@@ -65,27 +65,28 @@ class PonyfillReadableStream {
|
|
65
65
|
else {
|
66
66
|
let started = false;
|
67
67
|
let ongoing = false;
|
68
|
+
const readImpl = async (desiredSize) => {
|
69
|
+
if (!started) {
|
70
|
+
const controller = createController(desiredSize, this.readable);
|
71
|
+
started = true;
|
72
|
+
await underlyingSource?.start?.(controller);
|
73
|
+
controller._flush();
|
74
|
+
if (controller._closed) {
|
75
|
+
return;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
const controller = createController(desiredSize, this.readable);
|
79
|
+
await underlyingSource?.pull?.(controller);
|
80
|
+
controller._flush();
|
81
|
+
ongoing = false;
|
82
|
+
};
|
68
83
|
this.readable = new stream_1.Readable({
|
69
84
|
read(desiredSize) {
|
70
85
|
if (ongoing) {
|
71
86
|
return;
|
72
87
|
}
|
73
88
|
ongoing = true;
|
74
|
-
return
|
75
|
-
if (!started) {
|
76
|
-
const controller = createController(desiredSize, this);
|
77
|
-
started = true;
|
78
|
-
await underlyingSource?.start?.(controller);
|
79
|
-
controller._flush();
|
80
|
-
if (controller._closed) {
|
81
|
-
return;
|
82
|
-
}
|
83
|
-
}
|
84
|
-
const controller = createController(desiredSize, this);
|
85
|
-
await underlyingSource?.pull?.(controller);
|
86
|
-
controller._flush();
|
87
|
-
ongoing = false;
|
88
|
-
});
|
89
|
+
return readImpl(desiredSize);
|
89
90
|
},
|
90
91
|
destroy(err, callback) {
|
91
92
|
if (underlyingSource?.cancel) {
|
@@ -157,6 +158,17 @@ class PonyfillReadableStream {
|
|
157
158
|
tee() {
|
158
159
|
throw new Error('Not implemented');
|
159
160
|
}
|
161
|
+
async pipeToWriter(writer) {
|
162
|
+
try {
|
163
|
+
for await (const chunk of this) {
|
164
|
+
await writer.write(chunk);
|
165
|
+
}
|
166
|
+
await writer.close();
|
167
|
+
}
|
168
|
+
catch (err) {
|
169
|
+
await writer.abort(err);
|
170
|
+
}
|
171
|
+
}
|
160
172
|
pipeTo(destination) {
|
161
173
|
if (isPonyfillWritableStream(destination)) {
|
162
174
|
return new Promise((resolve, reject) => {
|
@@ -167,17 +179,7 @@ class PonyfillReadableStream {
|
|
167
179
|
}
|
168
180
|
else {
|
169
181
|
const writer = destination.getWriter();
|
170
|
-
return
|
171
|
-
try {
|
172
|
-
for await (const chunk of this) {
|
173
|
-
await writer.write(chunk);
|
174
|
-
}
|
175
|
-
await writer.close();
|
176
|
-
}
|
177
|
-
catch (err) {
|
178
|
-
await writer.abort(err);
|
179
|
-
}
|
180
|
-
});
|
182
|
+
return this.pipeToWriter(writer);
|
181
183
|
}
|
182
184
|
}
|
183
185
|
pipeThrough({ writable, readable, }) {
|
package/cjs/Request.js
CHANGED
@@ -5,6 +5,7 @@ const http_1 = require("http");
|
|
5
5
|
const https_1 = require("https");
|
6
6
|
const Body_js_1 = require("./Body.js");
|
7
7
|
const Headers_js_1 = require("./Headers.js");
|
8
|
+
const URL_js_1 = require("./URL.js");
|
8
9
|
function isRequest(input) {
|
9
10
|
return input[Symbol.toStringTag] === 'Request';
|
10
11
|
}
|
@@ -13,17 +14,26 @@ function isURL(obj) {
|
|
13
14
|
}
|
14
15
|
class PonyfillRequest extends Body_js_1.PonyfillBody {
|
15
16
|
constructor(input, options) {
|
16
|
-
let
|
17
|
+
let _url;
|
18
|
+
let _parsedUrl;
|
17
19
|
let bodyInit = null;
|
18
20
|
let requestInit;
|
19
21
|
if (typeof input === 'string') {
|
20
|
-
|
22
|
+
_url = input;
|
21
23
|
}
|
22
24
|
else if (isURL(input)) {
|
23
|
-
|
25
|
+
_parsedUrl = input;
|
24
26
|
}
|
25
27
|
else if (isRequest(input)) {
|
26
|
-
|
28
|
+
if (input._parsedUrl) {
|
29
|
+
_parsedUrl = input._parsedUrl;
|
30
|
+
}
|
31
|
+
else if (input._url) {
|
32
|
+
_url = input._url;
|
33
|
+
}
|
34
|
+
else {
|
35
|
+
_url = input.url;
|
36
|
+
}
|
27
37
|
bodyInit = input.body;
|
28
38
|
requestInit = input;
|
29
39
|
}
|
@@ -32,6 +42,8 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
|
|
32
42
|
requestInit = options;
|
33
43
|
}
|
34
44
|
super(bodyInit, options);
|
45
|
+
this._url = _url;
|
46
|
+
this._parsedUrl = _parsedUrl;
|
35
47
|
this.cache = requestInit?.cache || 'default';
|
36
48
|
this.credentials = requestInit?.credentials || 'same-origin';
|
37
49
|
this.headers =
|
@@ -48,20 +60,20 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
|
|
48
60
|
this._signal = requestInit?.signal;
|
49
61
|
this.headersSerializer = requestInit?.headersSerializer;
|
50
62
|
this.duplex = requestInit?.duplex || 'half';
|
51
|
-
this.url = url || '';
|
52
63
|
this.destination = 'document';
|
53
64
|
this.priority = 'auto';
|
54
65
|
if (this.method !== 'GET' && this.method !== 'HEAD') {
|
55
66
|
this.handleContentLengthHeader(true);
|
56
67
|
}
|
57
68
|
if (requestInit?.agent != null) {
|
69
|
+
const protocol = _parsedUrl?.protocol || _url || this.url;
|
58
70
|
if (requestInit.agent === false) {
|
59
71
|
this.agent = false;
|
60
72
|
}
|
61
|
-
else if (
|
73
|
+
else if (protocol.startsWith('http:') && requestInit.agent instanceof http_1.Agent) {
|
62
74
|
this.agent = requestInit.agent;
|
63
75
|
}
|
64
|
-
else if (
|
76
|
+
else if (protocol.startsWith('https:') && requestInit.agent instanceof https_1.Agent) {
|
65
77
|
this.agent = requestInit.agent;
|
66
78
|
}
|
67
79
|
}
|
@@ -79,7 +91,30 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
|
|
79
91
|
redirect;
|
80
92
|
referrer;
|
81
93
|
referrerPolicy;
|
82
|
-
|
94
|
+
_url;
|
95
|
+
get url() {
|
96
|
+
if (this._url == null) {
|
97
|
+
if (this._parsedUrl) {
|
98
|
+
this._url = this._parsedUrl.toString();
|
99
|
+
}
|
100
|
+
else {
|
101
|
+
throw new TypeError('Invalid URL');
|
102
|
+
}
|
103
|
+
}
|
104
|
+
return this._url;
|
105
|
+
}
|
106
|
+
_parsedUrl;
|
107
|
+
get parsedUrl() {
|
108
|
+
if (this._parsedUrl == null) {
|
109
|
+
if (this._url != null) {
|
110
|
+
this._parsedUrl = new URL_js_1.PonyfillURL(this._url);
|
111
|
+
}
|
112
|
+
else {
|
113
|
+
throw new TypeError('Invalid URL');
|
114
|
+
}
|
115
|
+
}
|
116
|
+
return this._parsedUrl;
|
117
|
+
}
|
83
118
|
duplex;
|
84
119
|
agent;
|
85
120
|
_signal;
|
package/cjs/URL.js
CHANGED
package/cjs/fetchNodeHttp.js
CHANGED
@@ -21,7 +21,7 @@ function getRequestFnForProtocol(url) {
|
|
21
21
|
function fetchNodeHttp(fetchRequest) {
|
22
22
|
return new Promise((resolve, reject) => {
|
23
23
|
try {
|
24
|
-
const requestFn = getRequestFnForProtocol(fetchRequest.url);
|
24
|
+
const requestFn = getRequestFnForProtocol(fetchRequest.parsedUrl?.protocol || fetchRequest.url);
|
25
25
|
const nodeReadable = (fetchRequest.body != null
|
26
26
|
? (0, utils_js_1.isNodeReadable)(fetchRequest.body)
|
27
27
|
? fetchRequest.body
|
@@ -32,12 +32,28 @@ function fetchNodeHttp(fetchRequest) {
|
|
32
32
|
if (nodeHeaders['accept-encoding'] == null) {
|
33
33
|
nodeHeaders['accept-encoding'] = 'gzip, deflate, br';
|
34
34
|
}
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
let nodeRequest;
|
36
|
+
if (fetchRequest.parsedUrl) {
|
37
|
+
nodeRequest = requestFn({
|
38
|
+
host: fetchRequest.parsedUrl.host,
|
39
|
+
hostname: fetchRequest.parsedUrl.hostname,
|
40
|
+
method: fetchRequest.method,
|
41
|
+
path: fetchRequest.parsedUrl.pathname + (fetchRequest.parsedUrl.search || ''),
|
42
|
+
port: fetchRequest.parsedUrl.port,
|
43
|
+
protocol: fetchRequest.parsedUrl.protocol,
|
44
|
+
headers: nodeHeaders,
|
45
|
+
signal: fetchRequest['_signal'] ?? undefined,
|
46
|
+
agent: fetchRequest.agent,
|
47
|
+
});
|
48
|
+
}
|
49
|
+
else {
|
50
|
+
nodeRequest = requestFn(fetchRequest.url, {
|
51
|
+
method: fetchRequest.method,
|
52
|
+
headers: nodeHeaders,
|
53
|
+
signal: fetchRequest['_signal'] ?? undefined,
|
54
|
+
agent: fetchRequest.agent,
|
55
|
+
});
|
56
|
+
}
|
41
57
|
nodeRequest.once('response', nodeResponse => {
|
42
58
|
let outputStream;
|
43
59
|
const contentEncoding = nodeResponse.headers['content-encoding'];
|
package/cjs/utils.js
CHANGED
@@ -14,11 +14,7 @@ function getHeadersObj(headers) {
|
|
14
14
|
if (headers == null || !isHeadersInstance(headers)) {
|
15
15
|
return headers;
|
16
16
|
}
|
17
|
-
|
18
|
-
headers.forEach((value, key) => {
|
19
|
-
obj[key] = value;
|
20
|
-
});
|
21
|
-
return obj;
|
17
|
+
return Object.fromEntries(headers.entries());
|
22
18
|
}
|
23
19
|
function defaultHeadersSerializer(headers, onContentLength) {
|
24
20
|
const headerArray = [];
|
package/esm/IteratorObject.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { inspect } from 'node:util';
|
2
|
+
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
2
3
|
import { isIterable } from './utils.js';
|
3
4
|
export class PonyfillIteratorObject {
|
4
5
|
iterableIterator;
|
@@ -107,10 +108,8 @@ export class PonyfillIteratorObject {
|
|
107
108
|
toArray() {
|
108
109
|
return Array.from(this.iterableIterator);
|
109
110
|
}
|
110
|
-
[
|
111
|
-
|
112
|
-
this.iterableIterator.return();
|
113
|
-
}
|
111
|
+
[DisposableSymbols.dispose]() {
|
112
|
+
this.iterableIterator.return?.();
|
114
113
|
}
|
115
114
|
next(...[value]) {
|
116
115
|
return this.iterableIterator.next(value);
|
package/esm/ReadableStream.js
CHANGED
@@ -62,27 +62,28 @@ export class PonyfillReadableStream {
|
|
62
62
|
else {
|
63
63
|
let started = false;
|
64
64
|
let ongoing = false;
|
65
|
+
const readImpl = async (desiredSize) => {
|
66
|
+
if (!started) {
|
67
|
+
const controller = createController(desiredSize, this.readable);
|
68
|
+
started = true;
|
69
|
+
await underlyingSource?.start?.(controller);
|
70
|
+
controller._flush();
|
71
|
+
if (controller._closed) {
|
72
|
+
return;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
const controller = createController(desiredSize, this.readable);
|
76
|
+
await underlyingSource?.pull?.(controller);
|
77
|
+
controller._flush();
|
78
|
+
ongoing = false;
|
79
|
+
};
|
65
80
|
this.readable = new Readable({
|
66
81
|
read(desiredSize) {
|
67
82
|
if (ongoing) {
|
68
83
|
return;
|
69
84
|
}
|
70
85
|
ongoing = true;
|
71
|
-
return
|
72
|
-
if (!started) {
|
73
|
-
const controller = createController(desiredSize, this);
|
74
|
-
started = true;
|
75
|
-
await underlyingSource?.start?.(controller);
|
76
|
-
controller._flush();
|
77
|
-
if (controller._closed) {
|
78
|
-
return;
|
79
|
-
}
|
80
|
-
}
|
81
|
-
const controller = createController(desiredSize, this);
|
82
|
-
await underlyingSource?.pull?.(controller);
|
83
|
-
controller._flush();
|
84
|
-
ongoing = false;
|
85
|
-
});
|
86
|
+
return readImpl(desiredSize);
|
86
87
|
},
|
87
88
|
destroy(err, callback) {
|
88
89
|
if (underlyingSource?.cancel) {
|
@@ -154,6 +155,17 @@ export class PonyfillReadableStream {
|
|
154
155
|
tee() {
|
155
156
|
throw new Error('Not implemented');
|
156
157
|
}
|
158
|
+
async pipeToWriter(writer) {
|
159
|
+
try {
|
160
|
+
for await (const chunk of this) {
|
161
|
+
await writer.write(chunk);
|
162
|
+
}
|
163
|
+
await writer.close();
|
164
|
+
}
|
165
|
+
catch (err) {
|
166
|
+
await writer.abort(err);
|
167
|
+
}
|
168
|
+
}
|
157
169
|
pipeTo(destination) {
|
158
170
|
if (isPonyfillWritableStream(destination)) {
|
159
171
|
return new Promise((resolve, reject) => {
|
@@ -164,17 +176,7 @@ export class PonyfillReadableStream {
|
|
164
176
|
}
|
165
177
|
else {
|
166
178
|
const writer = destination.getWriter();
|
167
|
-
return
|
168
|
-
try {
|
169
|
-
for await (const chunk of this) {
|
170
|
-
await writer.write(chunk);
|
171
|
-
}
|
172
|
-
await writer.close();
|
173
|
-
}
|
174
|
-
catch (err) {
|
175
|
-
await writer.abort(err);
|
176
|
-
}
|
177
|
-
});
|
179
|
+
return this.pipeToWriter(writer);
|
178
180
|
}
|
179
181
|
}
|
180
182
|
pipeThrough({ writable, readable, }) {
|
package/esm/Request.js
CHANGED
@@ -2,6 +2,7 @@ import { Agent as HTTPAgent } from 'http';
|
|
2
2
|
import { Agent as HTTPSAgent } from 'https';
|
3
3
|
import { PonyfillBody } from './Body.js';
|
4
4
|
import { isHeadersLike, PonyfillHeaders } from './Headers.js';
|
5
|
+
import { PonyfillURL } from './URL.js';
|
5
6
|
function isRequest(input) {
|
6
7
|
return input[Symbol.toStringTag] === 'Request';
|
7
8
|
}
|
@@ -10,17 +11,26 @@ function isURL(obj) {
|
|
10
11
|
}
|
11
12
|
export class PonyfillRequest extends PonyfillBody {
|
12
13
|
constructor(input, options) {
|
13
|
-
let
|
14
|
+
let _url;
|
15
|
+
let _parsedUrl;
|
14
16
|
let bodyInit = null;
|
15
17
|
let requestInit;
|
16
18
|
if (typeof input === 'string') {
|
17
|
-
|
19
|
+
_url = input;
|
18
20
|
}
|
19
21
|
else if (isURL(input)) {
|
20
|
-
|
22
|
+
_parsedUrl = input;
|
21
23
|
}
|
22
24
|
else if (isRequest(input)) {
|
23
|
-
|
25
|
+
if (input._parsedUrl) {
|
26
|
+
_parsedUrl = input._parsedUrl;
|
27
|
+
}
|
28
|
+
else if (input._url) {
|
29
|
+
_url = input._url;
|
30
|
+
}
|
31
|
+
else {
|
32
|
+
_url = input.url;
|
33
|
+
}
|
24
34
|
bodyInit = input.body;
|
25
35
|
requestInit = input;
|
26
36
|
}
|
@@ -29,6 +39,8 @@ export class PonyfillRequest extends PonyfillBody {
|
|
29
39
|
requestInit = options;
|
30
40
|
}
|
31
41
|
super(bodyInit, options);
|
42
|
+
this._url = _url;
|
43
|
+
this._parsedUrl = _parsedUrl;
|
32
44
|
this.cache = requestInit?.cache || 'default';
|
33
45
|
this.credentials = requestInit?.credentials || 'same-origin';
|
34
46
|
this.headers =
|
@@ -45,20 +57,20 @@ export class PonyfillRequest extends PonyfillBody {
|
|
45
57
|
this._signal = requestInit?.signal;
|
46
58
|
this.headersSerializer = requestInit?.headersSerializer;
|
47
59
|
this.duplex = requestInit?.duplex || 'half';
|
48
|
-
this.url = url || '';
|
49
60
|
this.destination = 'document';
|
50
61
|
this.priority = 'auto';
|
51
62
|
if (this.method !== 'GET' && this.method !== 'HEAD') {
|
52
63
|
this.handleContentLengthHeader(true);
|
53
64
|
}
|
54
65
|
if (requestInit?.agent != null) {
|
66
|
+
const protocol = _parsedUrl?.protocol || _url || this.url;
|
55
67
|
if (requestInit.agent === false) {
|
56
68
|
this.agent = false;
|
57
69
|
}
|
58
|
-
else if (
|
70
|
+
else if (protocol.startsWith('http:') && requestInit.agent instanceof HTTPAgent) {
|
59
71
|
this.agent = requestInit.agent;
|
60
72
|
}
|
61
|
-
else if (
|
73
|
+
else if (protocol.startsWith('https:') && requestInit.agent instanceof HTTPSAgent) {
|
62
74
|
this.agent = requestInit.agent;
|
63
75
|
}
|
64
76
|
}
|
@@ -76,7 +88,30 @@ export class PonyfillRequest extends PonyfillBody {
|
|
76
88
|
redirect;
|
77
89
|
referrer;
|
78
90
|
referrerPolicy;
|
79
|
-
|
91
|
+
_url;
|
92
|
+
get url() {
|
93
|
+
if (this._url == null) {
|
94
|
+
if (this._parsedUrl) {
|
95
|
+
this._url = this._parsedUrl.toString();
|
96
|
+
}
|
97
|
+
else {
|
98
|
+
throw new TypeError('Invalid URL');
|
99
|
+
}
|
100
|
+
}
|
101
|
+
return this._url;
|
102
|
+
}
|
103
|
+
_parsedUrl;
|
104
|
+
get parsedUrl() {
|
105
|
+
if (this._parsedUrl == null) {
|
106
|
+
if (this._url != null) {
|
107
|
+
this._parsedUrl = new PonyfillURL(this._url);
|
108
|
+
}
|
109
|
+
else {
|
110
|
+
throw new TypeError('Invalid URL');
|
111
|
+
}
|
112
|
+
}
|
113
|
+
return this._parsedUrl;
|
114
|
+
}
|
80
115
|
duplex;
|
81
116
|
agent;
|
82
117
|
_signal;
|
package/esm/URL.js
CHANGED
package/esm/fetchNodeHttp.js
CHANGED
@@ -18,7 +18,7 @@ function getRequestFnForProtocol(url) {
|
|
18
18
|
export function fetchNodeHttp(fetchRequest) {
|
19
19
|
return new Promise((resolve, reject) => {
|
20
20
|
try {
|
21
|
-
const requestFn = getRequestFnForProtocol(fetchRequest.url);
|
21
|
+
const requestFn = getRequestFnForProtocol(fetchRequest.parsedUrl?.protocol || fetchRequest.url);
|
22
22
|
const nodeReadable = (fetchRequest.body != null
|
23
23
|
? isNodeReadable(fetchRequest.body)
|
24
24
|
? fetchRequest.body
|
@@ -29,12 +29,28 @@ export function fetchNodeHttp(fetchRequest) {
|
|
29
29
|
if (nodeHeaders['accept-encoding'] == null) {
|
30
30
|
nodeHeaders['accept-encoding'] = 'gzip, deflate, br';
|
31
31
|
}
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
let nodeRequest;
|
33
|
+
if (fetchRequest.parsedUrl) {
|
34
|
+
nodeRequest = requestFn({
|
35
|
+
host: fetchRequest.parsedUrl.host,
|
36
|
+
hostname: fetchRequest.parsedUrl.hostname,
|
37
|
+
method: fetchRequest.method,
|
38
|
+
path: fetchRequest.parsedUrl.pathname + (fetchRequest.parsedUrl.search || ''),
|
39
|
+
port: fetchRequest.parsedUrl.port,
|
40
|
+
protocol: fetchRequest.parsedUrl.protocol,
|
41
|
+
headers: nodeHeaders,
|
42
|
+
signal: fetchRequest['_signal'] ?? undefined,
|
43
|
+
agent: fetchRequest.agent,
|
44
|
+
});
|
45
|
+
}
|
46
|
+
else {
|
47
|
+
nodeRequest = requestFn(fetchRequest.url, {
|
48
|
+
method: fetchRequest.method,
|
49
|
+
headers: nodeHeaders,
|
50
|
+
signal: fetchRequest['_signal'] ?? undefined,
|
51
|
+
agent: fetchRequest.agent,
|
52
|
+
});
|
53
|
+
}
|
38
54
|
nodeRequest.once('response', nodeResponse => {
|
39
55
|
let outputStream;
|
40
56
|
const contentEncoding = nodeResponse.headers['content-encoding'];
|
package/esm/utils.js
CHANGED
@@ -5,11 +5,7 @@ export function getHeadersObj(headers) {
|
|
5
5
|
if (headers == null || !isHeadersInstance(headers)) {
|
6
6
|
return headers;
|
7
7
|
}
|
8
|
-
|
9
|
-
headers.forEach((value, key) => {
|
10
|
-
obj[key] = value;
|
11
|
-
});
|
12
|
-
return obj;
|
8
|
+
return Object.fromEntries(headers.entries());
|
13
9
|
}
|
14
10
|
export function defaultHeadersSerializer(headers, onContentLength) {
|
15
11
|
const headerArray = [];
|
package/package.json
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "@whatwg-node/node-fetch",
|
3
|
-
"version": "0.7.
|
3
|
+
"version": "0.7.4-alpha-20241125125556-f6d4dd923d74499ecd7ef790e4704bf3bffd1892",
|
4
4
|
"description": "Fetch API implementation for Node",
|
5
5
|
"sideEffects": false,
|
6
6
|
"dependencies": {
|
7
7
|
"@kamilkisiela/fast-url-parser": "^1.1.4",
|
8
|
+
"@whatwg-node/disposablestack": "^0.0.5",
|
8
9
|
"busboy": "^1.6.0",
|
9
10
|
"fast-querystring": "^1.1.1",
|
10
11
|
"tslib": "^2.6.3"
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
1
2
|
export declare class PonyfillIteratorObject<T> implements IteratorObject<T, undefined, unknown> {
|
2
3
|
private iterableIterator;
|
3
4
|
[Symbol.toStringTag]: string;
|
@@ -13,7 +14,7 @@ export declare class PonyfillIteratorObject<T> implements IteratorObject<T, unde
|
|
13
14
|
every(predicate: (value: T, index: number) => unknown): boolean;
|
14
15
|
find(predicate: (value: T, index: number) => unknown): T | undefined;
|
15
16
|
toArray(): T[];
|
16
|
-
[
|
17
|
+
[DisposableSymbols.dispose](): void;
|
17
18
|
next(...[value]: [] | [unknown]): IteratorResult<T, undefined>;
|
18
19
|
[Symbol.iterator](): URLSearchParamsIterator<T>;
|
19
20
|
}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
1
2
|
export declare class PonyfillIteratorObject<T> implements IteratorObject<T, undefined, unknown> {
|
2
3
|
private iterableIterator;
|
3
4
|
[Symbol.toStringTag]: string;
|
@@ -13,7 +14,7 @@ export declare class PonyfillIteratorObject<T> implements IteratorObject<T, unde
|
|
13
14
|
every(predicate: (value: T, index: number) => unknown): boolean;
|
14
15
|
find(predicate: (value: T, index: number) => unknown): T | undefined;
|
15
16
|
toArray(): T[];
|
16
|
-
[
|
17
|
+
[DisposableSymbols.dispose](): void;
|
17
18
|
next(...[value]: [] | [unknown]): IteratorResult<T, undefined>;
|
18
19
|
[Symbol.iterator](): URLSearchParamsIterator<T>;
|
19
20
|
}
|
@@ -10,6 +10,7 @@ export declare class PonyfillReadableStream<T> implements ReadableStream<T> {
|
|
10
10
|
getReader(): ReadableStreamDefaultReader<T>;
|
11
11
|
[Symbol.asyncIterator](): NodeJS.AsyncIterator<any, any, any>;
|
12
12
|
tee(): [ReadableStream<T>, ReadableStream<T>];
|
13
|
+
private pipeToWriter;
|
13
14
|
pipeTo(destination: WritableStream<T>): Promise<void>;
|
14
15
|
pipeThrough<T2>({ writable, readable, }: {
|
15
16
|
writable: WritableStream<T>;
|
@@ -10,6 +10,7 @@ export declare class PonyfillReadableStream<T> implements ReadableStream<T> {
|
|
10
10
|
getReader(): ReadableStreamDefaultReader<T>;
|
11
11
|
[Symbol.asyncIterator](): NodeJS.AsyncIterator<any, any, any>;
|
12
12
|
tee(): [ReadableStream<T>, ReadableStream<T>];
|
13
|
+
private pipeToWriter;
|
13
14
|
pipeTo(destination: WritableStream<T>): Promise<void>;
|
14
15
|
pipeThrough<T2>({ writable, readable, }: {
|
15
16
|
writable: WritableStream<T>;
|
package/typings/Request.d.cts
CHANGED
@@ -25,7 +25,10 @@ export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> im
|
|
25
25
|
redirect: RequestRedirect;
|
26
26
|
referrer: string;
|
27
27
|
referrerPolicy: ReferrerPolicy;
|
28
|
-
|
28
|
+
_url: string | undefined;
|
29
|
+
get url(): string;
|
30
|
+
_parsedUrl: URL | undefined;
|
31
|
+
get parsedUrl(): URL;
|
29
32
|
duplex: 'half' | 'full';
|
30
33
|
agent: HTTPAgent | HTTPSAgent | false | undefined;
|
31
34
|
private _signal;
|
package/typings/Request.d.ts
CHANGED
@@ -25,7 +25,10 @@ export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> im
|
|
25
25
|
redirect: RequestRedirect;
|
26
26
|
referrer: string;
|
27
27
|
referrerPolicy: ReferrerPolicy;
|
28
|
-
|
28
|
+
_url: string | undefined;
|
29
|
+
get url(): string;
|
30
|
+
_parsedUrl: URL | undefined;
|
31
|
+
get parsedUrl(): URL;
|
29
32
|
duplex: 'half' | 'full';
|
30
33
|
agent: HTTPAgent | HTTPSAgent | false | undefined;
|
31
34
|
private _signal;
|
package/typings/URL.d.cts
CHANGED
@@ -16,4 +16,5 @@ export declare class PonyfillURL extends FastUrl implements URL {
|
|
16
16
|
static createObjectURL(blob: Blob): string;
|
17
17
|
static resolveObjectURL(url: string): void;
|
18
18
|
static getBlobFromURL(url: string): Blob | PonyfillBlob | undefined;
|
19
|
+
[Symbol.toStringTag]: string;
|
19
20
|
}
|
package/typings/URL.d.ts
CHANGED
@@ -16,4 +16,5 @@ export declare class PonyfillURL extends FastUrl implements URL {
|
|
16
16
|
static createObjectURL(blob: Blob): string;
|
17
17
|
static resolveObjectURL(url: string): void;
|
18
18
|
static getBlobFromURL(url: string): Blob | PonyfillBlob | undefined;
|
19
|
+
[Symbol.toStringTag]: string;
|
19
20
|
}
|