@whatwg-node/node-fetch 0.7.9-alpha-20250213114720-f8ce00aa9982aa0655656a02c3359ad4136d57ce → 0.7.9-alpha-20250213122700-6a189724db9ab6211349779c44665b0b4f1006af
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/Headers.js +1 -1
- package/cjs/fetch.js +32 -4
- package/cjs/fetchCurl.js +8 -1
- package/esm/Headers.js +1 -1
- package/esm/fetch.js +33 -5
- package/esm/fetchCurl.js +8 -1
- package/package.json +1 -1
package/cjs/Headers.js
CHANGED
@@ -247,7 +247,7 @@ class PonyfillHeaders {
|
|
247
247
|
record['set-cookie'] = this._setCookies;
|
248
248
|
}
|
249
249
|
else {
|
250
|
-
record[key] = value
|
250
|
+
record[key] = value?.includes(',') ? value.split(',').map(el => el.trim()) : value;
|
251
251
|
}
|
252
252
|
});
|
253
253
|
return `Headers ${(0, node_util_1.inspect)(record)}`;
|
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
@@ -151,7 +151,14 @@ function fetchCurl(fetchRequest) {
|
|
151
151
|
});
|
152
152
|
}
|
153
153
|
else {
|
154
|
-
|
154
|
+
try {
|
155
|
+
curlHandle.perform();
|
156
|
+
}
|
157
|
+
catch (e) {
|
158
|
+
setImmediate(() => {
|
159
|
+
curlHandle.perform();
|
160
|
+
});
|
161
|
+
}
|
155
162
|
}
|
156
163
|
return deferredPromise.promise;
|
157
164
|
}
|
package/esm/Headers.js
CHANGED
@@ -243,7 +243,7 @@ export class PonyfillHeaders {
|
|
243
243
|
record['set-cookie'] = this._setCookies;
|
244
244
|
}
|
245
245
|
else {
|
246
|
-
record[key] = value
|
246
|
+
record[key] = value?.includes(',') ? value.split(',').map(el => el.trim()) : value;
|
247
247
|
}
|
248
248
|
});
|
249
249
|
return `Headers ${inspect(record)}`;
|
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
@@ -148,7 +148,14 @@ export function fetchCurl(fetchRequest) {
|
|
148
148
|
});
|
149
149
|
}
|
150
150
|
else {
|
151
|
-
|
151
|
+
try {
|
152
|
+
curlHandle.perform();
|
153
|
+
}
|
154
|
+
catch (e) {
|
155
|
+
setImmediate(() => {
|
156
|
+
curlHandle.perform();
|
157
|
+
});
|
158
|
+
}
|
152
159
|
}
|
153
160
|
return deferredPromise.promise;
|
154
161
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@whatwg-node/node-fetch",
|
3
|
-
"version": "0.7.9-alpha-
|
3
|
+
"version": "0.7.9-alpha-20250213122700-6a189724db9ab6211349779c44665b0b4f1006af",
|
4
4
|
"description": "Fetch API implementation for Node",
|
5
5
|
"sideEffects": false,
|
6
6
|
"dependencies": {
|