@whatwg-node/node-fetch 0.5.16 → 0.5.17-alpha-20240726115125-ab31308a7b0579cdd0a19007f92db672cf1eaa85
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/fetchCurl.js +18 -13
- package/cjs/fetchNodeHttp.js +18 -24
- package/esm/fetchCurl.js +19 -14
- package/esm/fetchNodeHttp.js +19 -25
- package/package.json +1 -1
package/cjs/fetchCurl.js
CHANGED
@@ -81,7 +81,18 @@ function fetchCurl(fetchRequest) {
|
|
81
81
|
curlHandle.close();
|
82
82
|
});
|
83
83
|
curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
|
84
|
-
const
|
84
|
+
const outputStream = new stream_1.PassThrough();
|
85
|
+
stream_1.promises
|
86
|
+
.pipeline(stream, outputStream, {
|
87
|
+
end: true,
|
88
|
+
signal: fetchRequest['_signal'] ?? undefined,
|
89
|
+
})
|
90
|
+
.then(() => {
|
91
|
+
if (!stream.destroyed) {
|
92
|
+
stream.resume();
|
93
|
+
}
|
94
|
+
})
|
95
|
+
.catch(reject);
|
85
96
|
const headersFlat = headersBuf
|
86
97
|
.toString('utf8')
|
87
98
|
.split(/\r?\n|\r/g)
|
@@ -89,7 +100,10 @@ function fetchCurl(fetchRequest) {
|
|
89
100
|
if (headerFilter && !headerFilter.startsWith('HTTP/')) {
|
90
101
|
if (fetchRequest.redirect === 'error' &&
|
91
102
|
(headerFilter.includes('location') || headerFilter.includes('Location'))) {
|
92
|
-
|
103
|
+
if (!stream.destroyed) {
|
104
|
+
stream.resume();
|
105
|
+
}
|
106
|
+
outputStream.destroy();
|
93
107
|
reject(new Error('redirect is not allowed'));
|
94
108
|
}
|
95
109
|
return true;
|
@@ -97,22 +111,13 @@ function fetchCurl(fetchRequest) {
|
|
97
111
|
return false;
|
98
112
|
});
|
99
113
|
const headersInit = headersFlat.map(headerFlat => headerFlat.split(/:\s(.+)/).slice(0, 2));
|
100
|
-
|
101
|
-
stream.pause();
|
102
|
-
});
|
103
|
-
pipedStream.on('resume', () => {
|
104
|
-
stream.resume();
|
105
|
-
});
|
106
|
-
pipedStream.on('close', () => {
|
107
|
-
stream.destroy();
|
108
|
-
});
|
109
|
-
const ponyfillResponse = new Response_js_1.PonyfillResponse(pipedStream, {
|
114
|
+
const ponyfillResponse = new Response_js_1.PonyfillResponse(outputStream, {
|
110
115
|
status,
|
111
116
|
headers: headersInit,
|
112
117
|
url: fetchRequest.url,
|
113
118
|
});
|
114
119
|
resolve(ponyfillResponse);
|
115
|
-
streamResolved =
|
120
|
+
streamResolved = outputStream;
|
116
121
|
});
|
117
122
|
curlHandle.perform();
|
118
123
|
});
|
package/cjs/fetchNodeHttp.js
CHANGED
@@ -5,7 +5,6 @@ const http_1 = require("http");
|
|
5
5
|
const https_1 = require("https");
|
6
6
|
const stream_1 = require("stream");
|
7
7
|
const zlib_1 = require("zlib");
|
8
|
-
const AbortError_js_1 = require("./AbortError.js");
|
9
8
|
const Request_js_1 = require("./Request.js");
|
10
9
|
const Response_js_1 = require("./Response.js");
|
11
10
|
const URL_js_1 = require("./URL.js");
|
@@ -40,24 +39,26 @@ function fetchNodeHttp(fetchRequest) {
|
|
40
39
|
agent: fetchRequest.agent,
|
41
40
|
});
|
42
41
|
nodeRequest.once('response', nodeResponse => {
|
43
|
-
let
|
42
|
+
let outputStream;
|
44
43
|
const contentEncoding = nodeResponse.headers['content-encoding'];
|
45
44
|
switch (contentEncoding) {
|
46
45
|
case 'x-gzip':
|
47
46
|
case 'gzip':
|
48
|
-
|
47
|
+
outputStream = (0, zlib_1.createGunzip)();
|
49
48
|
break;
|
50
49
|
case 'x-deflate':
|
51
50
|
case 'deflate':
|
52
|
-
|
51
|
+
outputStream = (0, zlib_1.createInflate)();
|
53
52
|
break;
|
54
53
|
case 'x-deflate-raw':
|
55
54
|
case 'deflate-raw':
|
56
|
-
|
55
|
+
outputStream = (0, zlib_1.createInflateRaw)();
|
57
56
|
break;
|
58
57
|
case 'br':
|
59
|
-
|
58
|
+
outputStream = (0, zlib_1.createBrotliDecompress)();
|
60
59
|
break;
|
60
|
+
default:
|
61
|
+
outputStream = new stream_1.PassThrough();
|
61
62
|
}
|
62
63
|
if (nodeResponse.headers.location) {
|
63
64
|
if (fetchRequest.redirect === 'error') {
|
@@ -77,25 +78,18 @@ function fetchNodeHttp(fetchRequest) {
|
|
77
78
|
return;
|
78
79
|
}
|
79
80
|
}
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
81
|
+
stream_1.promises
|
82
|
+
.pipeline(nodeResponse, outputStream, {
|
83
|
+
signal: fetchRequest['_signal'] ?? undefined,
|
84
|
+
end: true,
|
85
|
+
})
|
86
|
+
.then(() => {
|
87
|
+
if (!nodeResponse.destroyed) {
|
86
88
|
nodeResponse.resume();
|
87
|
-
}
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
fetchRequest['_signal']?.addEventListener('abort', () => {
|
92
|
-
if (!nodeResponse.destroyed) {
|
93
|
-
responseBody.emit('error', new AbortError_js_1.PonyfillAbortError());
|
94
|
-
}
|
95
|
-
});
|
96
|
-
}
|
97
|
-
nodeResponse.once('error', reject);
|
98
|
-
const ponyfillResponse = new Response_js_1.PonyfillResponse(responseBody, {
|
89
|
+
}
|
90
|
+
})
|
91
|
+
.catch(reject);
|
92
|
+
const ponyfillResponse = new Response_js_1.PonyfillResponse(outputStream, {
|
99
93
|
status: nodeResponse.statusCode,
|
100
94
|
statusText: nodeResponse.statusMessage,
|
101
95
|
headers: nodeResponse.headers,
|
package/esm/fetchCurl.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { PassThrough, Readable } from 'stream';
|
1
|
+
import { PassThrough, Readable, promises as streamPromises } from 'stream';
|
2
2
|
import { PonyfillResponse } from './Response.js';
|
3
3
|
import { defaultHeadersSerializer, isNodeReadable } from './utils.js';
|
4
4
|
export function fetchCurl(fetchRequest) {
|
@@ -78,7 +78,18 @@ export function fetchCurl(fetchRequest) {
|
|
78
78
|
curlHandle.close();
|
79
79
|
});
|
80
80
|
curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
|
81
|
-
const
|
81
|
+
const outputStream = new PassThrough();
|
82
|
+
streamPromises
|
83
|
+
.pipeline(stream, outputStream, {
|
84
|
+
end: true,
|
85
|
+
signal: fetchRequest['_signal'] ?? undefined,
|
86
|
+
})
|
87
|
+
.then(() => {
|
88
|
+
if (!stream.destroyed) {
|
89
|
+
stream.resume();
|
90
|
+
}
|
91
|
+
})
|
92
|
+
.catch(reject);
|
82
93
|
const headersFlat = headersBuf
|
83
94
|
.toString('utf8')
|
84
95
|
.split(/\r?\n|\r/g)
|
@@ -86,7 +97,10 @@ export function fetchCurl(fetchRequest) {
|
|
86
97
|
if (headerFilter && !headerFilter.startsWith('HTTP/')) {
|
87
98
|
if (fetchRequest.redirect === 'error' &&
|
88
99
|
(headerFilter.includes('location') || headerFilter.includes('Location'))) {
|
89
|
-
|
100
|
+
if (!stream.destroyed) {
|
101
|
+
stream.resume();
|
102
|
+
}
|
103
|
+
outputStream.destroy();
|
90
104
|
reject(new Error('redirect is not allowed'));
|
91
105
|
}
|
92
106
|
return true;
|
@@ -94,22 +108,13 @@ export function fetchCurl(fetchRequest) {
|
|
94
108
|
return false;
|
95
109
|
});
|
96
110
|
const headersInit = headersFlat.map(headerFlat => headerFlat.split(/:\s(.+)/).slice(0, 2));
|
97
|
-
|
98
|
-
stream.pause();
|
99
|
-
});
|
100
|
-
pipedStream.on('resume', () => {
|
101
|
-
stream.resume();
|
102
|
-
});
|
103
|
-
pipedStream.on('close', () => {
|
104
|
-
stream.destroy();
|
105
|
-
});
|
106
|
-
const ponyfillResponse = new PonyfillResponse(pipedStream, {
|
111
|
+
const ponyfillResponse = new PonyfillResponse(outputStream, {
|
107
112
|
status,
|
108
113
|
headers: headersInit,
|
109
114
|
url: fetchRequest.url,
|
110
115
|
});
|
111
116
|
resolve(ponyfillResponse);
|
112
|
-
streamResolved =
|
117
|
+
streamResolved = outputStream;
|
113
118
|
});
|
114
119
|
curlHandle.perform();
|
115
120
|
});
|
package/esm/fetchNodeHttp.js
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
import { request as httpRequest } from 'http';
|
2
2
|
import { request as httpsRequest } from 'https';
|
3
|
-
import { PassThrough, Readable } from 'stream';
|
3
|
+
import { PassThrough, Readable, promises as streamPromises } from 'stream';
|
4
4
|
import { createBrotliDecompress, createGunzip, createInflate, createInflateRaw } from 'zlib';
|
5
|
-
import { PonyfillAbortError } from './AbortError.js';
|
6
5
|
import { PonyfillRequest } from './Request.js';
|
7
6
|
import { PonyfillResponse } from './Response.js';
|
8
7
|
import { PonyfillURL } from './URL.js';
|
@@ -37,24 +36,26 @@ export function fetchNodeHttp(fetchRequest) {
|
|
37
36
|
agent: fetchRequest.agent,
|
38
37
|
});
|
39
38
|
nodeRequest.once('response', nodeResponse => {
|
40
|
-
let
|
39
|
+
let outputStream;
|
41
40
|
const contentEncoding = nodeResponse.headers['content-encoding'];
|
42
41
|
switch (contentEncoding) {
|
43
42
|
case 'x-gzip':
|
44
43
|
case 'gzip':
|
45
|
-
|
44
|
+
outputStream = createGunzip();
|
46
45
|
break;
|
47
46
|
case 'x-deflate':
|
48
47
|
case 'deflate':
|
49
|
-
|
48
|
+
outputStream = createInflate();
|
50
49
|
break;
|
51
50
|
case 'x-deflate-raw':
|
52
51
|
case 'deflate-raw':
|
53
|
-
|
52
|
+
outputStream = createInflateRaw();
|
54
53
|
break;
|
55
54
|
case 'br':
|
56
|
-
|
55
|
+
outputStream = createBrotliDecompress();
|
57
56
|
break;
|
57
|
+
default:
|
58
|
+
outputStream = new PassThrough();
|
58
59
|
}
|
59
60
|
if (nodeResponse.headers.location) {
|
60
61
|
if (fetchRequest.redirect === 'error') {
|
@@ -74,25 +75,18 @@ export function fetchNodeHttp(fetchRequest) {
|
|
74
75
|
return;
|
75
76
|
}
|
76
77
|
}
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
78
|
+
streamPromises
|
79
|
+
.pipeline(nodeResponse, outputStream, {
|
80
|
+
signal: fetchRequest['_signal'] ?? undefined,
|
81
|
+
end: true,
|
82
|
+
})
|
83
|
+
.then(() => {
|
84
|
+
if (!nodeResponse.destroyed) {
|
83
85
|
nodeResponse.resume();
|
84
|
-
}
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
fetchRequest['_signal']?.addEventListener('abort', () => {
|
89
|
-
if (!nodeResponse.destroyed) {
|
90
|
-
responseBody.emit('error', new PonyfillAbortError());
|
91
|
-
}
|
92
|
-
});
|
93
|
-
}
|
94
|
-
nodeResponse.once('error', reject);
|
95
|
-
const ponyfillResponse = new PonyfillResponse(responseBody, {
|
86
|
+
}
|
87
|
+
})
|
88
|
+
.catch(reject);
|
89
|
+
const ponyfillResponse = new PonyfillResponse(outputStream, {
|
96
90
|
status: nodeResponse.statusCode,
|
97
91
|
statusText: nodeResponse.statusMessage,
|
98
92
|
headers: nodeResponse.headers,
|
package/package.json
CHANGED