@whatwg-node/node-fetch 0.7.9-alpha-20250213115905-c3512e5da088f8ddf908e6a2fdf8b86288cfb74a → 0.7.9-rc-20250213120211-2e564250f0d6354be9db6c60c01427b07608eed5
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/fetch.js +32 -4
- package/cjs/fetchCurl.js +1 -2
- package/cjs/fetchNodeHttp.js +1 -1
- package/cjs/utils.js +0 -4
- package/esm/fetch.js +33 -5
- package/esm/fetchCurl.js +2 -3
- package/esm/fetchNodeHttp.js +2 -2
- package/esm/utils.js +0 -3
- package/package.json +1 -1
- package/typings/utils.d.cts +0 -1
- package/typings/utils.d.ts +0 -1
package/cjs/fetch.js
CHANGED
@@ -11,10 +11,38 @@ const Response_js_1 = require("./Response.js");
|
|
11
11
|
const URL_js_1 = require("./URL.js");
|
12
12
|
const utils_js_1 = require("./utils.js");
|
13
13
|
const BASE64_SUFFIX = ';base64';
|
14
|
-
function getResponseForFile(url) {
|
14
|
+
async function getResponseForFile(url) {
|
15
15
|
const path = (0, node_url_1.fileURLToPath)(url);
|
16
|
-
|
17
|
-
|
16
|
+
try {
|
17
|
+
await node_fs_1.promises.access(path, node_fs_1.promises.constants.R_OK);
|
18
|
+
const stats = await node_fs_1.promises.stat(path, {
|
19
|
+
bigint: true,
|
20
|
+
});
|
21
|
+
const readable = (0, node_fs_1.createReadStream)(path);
|
22
|
+
return new Response_js_1.PonyfillResponse(readable, {
|
23
|
+
status: 200,
|
24
|
+
statusText: 'OK',
|
25
|
+
headers: {
|
26
|
+
'content-type': 'application/octet-stream',
|
27
|
+
'last-modified': stats.mtime.toUTCString(),
|
28
|
+
},
|
29
|
+
});
|
30
|
+
}
|
31
|
+
catch (err) {
|
32
|
+
if (err.code === 'ENOENT') {
|
33
|
+
return new Response_js_1.PonyfillResponse(null, {
|
34
|
+
status: 404,
|
35
|
+
statusText: 'Not Found',
|
36
|
+
});
|
37
|
+
}
|
38
|
+
else if (err.code === 'EACCES') {
|
39
|
+
return new Response_js_1.PonyfillResponse(null, {
|
40
|
+
status: 403,
|
41
|
+
statusText: 'Forbidden',
|
42
|
+
});
|
43
|
+
}
|
44
|
+
throw err;
|
45
|
+
}
|
18
46
|
}
|
19
47
|
function getResponseForDataUri(url) {
|
20
48
|
const [mimeType = 'text/plain', ...datas] = url.substring(5).split(',');
|
@@ -66,7 +94,7 @@ function fetchPonyfill(info, init) {
|
|
66
94
|
}
|
67
95
|
if (fetchRequest.url.startsWith('file:')) {
|
68
96
|
const response = getResponseForFile(fetchRequest.url);
|
69
|
-
return
|
97
|
+
return response;
|
70
98
|
}
|
71
99
|
if (fetchRequest.url.startsWith('blob:')) {
|
72
100
|
const response = getResponseForBlob(fetchRequest.url);
|
package/cjs/fetchCurl.js
CHANGED
@@ -118,8 +118,7 @@ function fetchCurl(fetchRequest) {
|
|
118
118
|
.filter(headerFilter => {
|
119
119
|
if (headerFilter && !headerFilter.startsWith('HTTP/')) {
|
120
120
|
if (fetchRequest.redirect === 'error' &&
|
121
|
-
headerFilter.
|
122
|
-
(0, utils_js_1.shouldRedirect)(status)) {
|
121
|
+
(headerFilter.includes('location') || headerFilter.includes('Location'))) {
|
123
122
|
if (!stream.destroyed) {
|
124
123
|
stream.resume();
|
125
124
|
}
|
package/cjs/fetchNodeHttp.js
CHANGED
@@ -73,7 +73,7 @@ function fetchNodeHttp(fetchRequest) {
|
|
73
73
|
default:
|
74
74
|
outputStream = new node_stream_1.PassThrough();
|
75
75
|
}
|
76
|
-
if (nodeResponse.headers.location
|
76
|
+
if (nodeResponse.headers.location) {
|
77
77
|
if (fetchRequest.redirect === 'error') {
|
78
78
|
const redirectError = new Error('Redirects are not allowed');
|
79
79
|
reject(redirectError);
|
package/cjs/utils.js
CHANGED
@@ -7,7 +7,6 @@ exports.isArrayBufferView = isArrayBufferView;
|
|
7
7
|
exports.isNodeReadable = isNodeReadable;
|
8
8
|
exports.createDeferredPromise = createDeferredPromise;
|
9
9
|
exports.isIterable = isIterable;
|
10
|
-
exports.shouldRedirect = shouldRedirect;
|
11
10
|
function isHeadersInstance(obj) {
|
12
11
|
return obj?.forEach != null;
|
13
12
|
}
|
@@ -89,6 +88,3 @@ function createDeferredPromise() {
|
|
89
88
|
function isIterable(value) {
|
90
89
|
return value?.[Symbol.iterator] != null;
|
91
90
|
}
|
92
|
-
function shouldRedirect(status) {
|
93
|
-
return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
|
94
|
-
}
|
package/esm/fetch.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
2
|
-
import { createReadStream } from 'node:fs';
|
2
|
+
import { createReadStream, promises as fsPromises } from 'node:fs';
|
3
3
|
import { fileURLToPath } from 'node:url';
|
4
4
|
import { fetchCurl } from './fetchCurl.js';
|
5
5
|
import { fetchNodeHttp } from './fetchNodeHttp.js';
|
@@ -8,10 +8,38 @@ import { PonyfillResponse } from './Response.js';
|
|
8
8
|
import { PonyfillURL } from './URL.js';
|
9
9
|
import { fakePromise } from './utils.js';
|
10
10
|
const BASE64_SUFFIX = ';base64';
|
11
|
-
function getResponseForFile(url) {
|
11
|
+
async function getResponseForFile(url) {
|
12
12
|
const path = fileURLToPath(url);
|
13
|
-
|
14
|
-
|
13
|
+
try {
|
14
|
+
await fsPromises.access(path, fsPromises.constants.R_OK);
|
15
|
+
const stats = await fsPromises.stat(path, {
|
16
|
+
bigint: true,
|
17
|
+
});
|
18
|
+
const readable = createReadStream(path);
|
19
|
+
return new PonyfillResponse(readable, {
|
20
|
+
status: 200,
|
21
|
+
statusText: 'OK',
|
22
|
+
headers: {
|
23
|
+
'content-type': 'application/octet-stream',
|
24
|
+
'last-modified': stats.mtime.toUTCString(),
|
25
|
+
},
|
26
|
+
});
|
27
|
+
}
|
28
|
+
catch (err) {
|
29
|
+
if (err.code === 'ENOENT') {
|
30
|
+
return new PonyfillResponse(null, {
|
31
|
+
status: 404,
|
32
|
+
statusText: 'Not Found',
|
33
|
+
});
|
34
|
+
}
|
35
|
+
else if (err.code === 'EACCES') {
|
36
|
+
return new PonyfillResponse(null, {
|
37
|
+
status: 403,
|
38
|
+
statusText: 'Forbidden',
|
39
|
+
});
|
40
|
+
}
|
41
|
+
throw err;
|
42
|
+
}
|
15
43
|
}
|
16
44
|
function getResponseForDataUri(url) {
|
17
45
|
const [mimeType = 'text/plain', ...datas] = url.substring(5).split(',');
|
@@ -63,7 +91,7 @@ export function fetchPonyfill(info, init) {
|
|
63
91
|
}
|
64
92
|
if (fetchRequest.url.startsWith('file:')) {
|
65
93
|
const response = getResponseForFile(fetchRequest.url);
|
66
|
-
return
|
94
|
+
return response;
|
67
95
|
}
|
68
96
|
if (fetchRequest.url.startsWith('blob:')) {
|
69
97
|
const response = getResponseForBlob(fetchRequest.url);
|
package/esm/fetchCurl.js
CHANGED
@@ -2,7 +2,7 @@ import { PassThrough, Readable } from 'node:stream';
|
|
2
2
|
import { pipeline } from 'node:stream/promises';
|
3
3
|
import { rootCertificates } from 'node:tls';
|
4
4
|
import { PonyfillResponse } from './Response.js';
|
5
|
-
import { createDeferredPromise, defaultHeadersSerializer, isNodeReadable
|
5
|
+
import { createDeferredPromise, defaultHeadersSerializer, isNodeReadable } from './utils.js';
|
6
6
|
export function fetchCurl(fetchRequest) {
|
7
7
|
const { Curl, CurlFeature, CurlPause, CurlProgressFunc } = globalThis['libcurl'];
|
8
8
|
const curlHandle = new Curl();
|
@@ -115,8 +115,7 @@ export function fetchCurl(fetchRequest) {
|
|
115
115
|
.filter(headerFilter => {
|
116
116
|
if (headerFilter && !headerFilter.startsWith('HTTP/')) {
|
117
117
|
if (fetchRequest.redirect === 'error' &&
|
118
|
-
headerFilter.
|
119
|
-
shouldRedirect(status)) {
|
118
|
+
(headerFilter.includes('location') || headerFilter.includes('Location'))) {
|
120
119
|
if (!stream.destroyed) {
|
121
120
|
stream.resume();
|
122
121
|
}
|
package/esm/fetchNodeHttp.js
CHANGED
@@ -6,7 +6,7 @@ import { createBrotliDecompress, createGunzip, createInflate, createInflateRaw }
|
|
6
6
|
import { PonyfillRequest } from './Request.js';
|
7
7
|
import { PonyfillResponse } from './Response.js';
|
8
8
|
import { PonyfillURL } from './URL.js';
|
9
|
-
import { getHeadersObj, isNodeReadable
|
9
|
+
import { getHeadersObj, isNodeReadable } from './utils.js';
|
10
10
|
function getRequestFnForProtocol(url) {
|
11
11
|
if (url.startsWith('http:')) {
|
12
12
|
return httpRequest;
|
@@ -70,7 +70,7 @@ export function fetchNodeHttp(fetchRequest) {
|
|
70
70
|
default:
|
71
71
|
outputStream = new PassThrough();
|
72
72
|
}
|
73
|
-
if (nodeResponse.headers.location
|
73
|
+
if (nodeResponse.headers.location) {
|
74
74
|
if (fetchRequest.redirect === 'error') {
|
75
75
|
const redirectError = new Error('Redirects are not allowed');
|
76
76
|
reject(redirectError);
|
package/esm/utils.js
CHANGED
@@ -79,6 +79,3 @@ export function createDeferredPromise() {
|
|
79
79
|
export function isIterable(value) {
|
80
80
|
return value?.[Symbol.iterator] != null;
|
81
81
|
}
|
82
|
-
export function shouldRedirect(status) {
|
83
|
-
return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
|
84
|
-
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@whatwg-node/node-fetch",
|
3
|
-
"version": "0.7.9-
|
3
|
+
"version": "0.7.9-rc-20250213120211-2e564250f0d6354be9db6c60c01427b07608eed5",
|
4
4
|
"description": "Fetch API implementation for Node",
|
5
5
|
"sideEffects": false,
|
6
6
|
"dependencies": {
|
package/typings/utils.d.cts
CHANGED
@@ -11,4 +11,3 @@ export interface DeferredPromise<T = void> {
|
|
11
11
|
}
|
12
12
|
export declare function createDeferredPromise<T = void>(): DeferredPromise<T>;
|
13
13
|
export declare function isIterable(value: any): value is Iterable<unknown>;
|
14
|
-
export declare function shouldRedirect(status?: number): boolean;
|
package/typings/utils.d.ts
CHANGED
@@ -11,4 +11,3 @@ export interface DeferredPromise<T = void> {
|
|
11
11
|
}
|
12
12
|
export declare function createDeferredPromise<T = void>(): DeferredPromise<T>;
|
13
13
|
export declare function isIterable(value: any): value is Iterable<unknown>;
|
14
|
-
export declare function shouldRedirect(status?: number): boolean;
|