@whatwg-node/node-fetch 0.4.12 → 0.4.13
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 +14 -5
- package/esm/fetchCurl.js +14 -5
- package/package.json +1 -1
package/cjs/fetchCurl.js
CHANGED
@@ -2,16 +2,12 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.fetchCurl = void 0;
|
4
4
|
const node_stream_1 = require("node:stream");
|
5
|
+
const AbortError_js_1 = require("./AbortError.js");
|
5
6
|
const Response_js_1 = require("./Response.js");
|
6
7
|
const utils_js_1 = require("./utils.js");
|
7
8
|
function fetchCurl(fetchRequest) {
|
8
9
|
const { Curl, CurlCode, CurlFeature, CurlPause, CurlProgressFunc } = globalThis['libcurl'];
|
9
10
|
const curlHandle = new Curl();
|
10
|
-
if (fetchRequest['_signal']) {
|
11
|
-
fetchRequest['_signal'].onabort = () => {
|
12
|
-
curlHandle.pause(CurlPause.Recv);
|
13
|
-
};
|
14
|
-
}
|
15
11
|
curlHandle.enable(CurlFeature.NoDataParsing);
|
16
12
|
curlHandle.setOpt('URL', fetchRequest.url);
|
17
13
|
curlHandle.setOpt('SSL_VERIFYPEER', false);
|
@@ -57,6 +53,18 @@ function fetchCurl(fetchRequest) {
|
|
57
53
|
curlHandle.setOpt('HTTPHEADER', curlHeaders);
|
58
54
|
curlHandle.enable(CurlFeature.NoHeaderParsing);
|
59
55
|
return new Promise(function promiseResolver(resolve, reject) {
|
56
|
+
let streamResolved = false;
|
57
|
+
if (fetchRequest['_signal']) {
|
58
|
+
fetchRequest['_signal'].onabort = () => {
|
59
|
+
if (streamResolved) {
|
60
|
+
curlHandle.pause(CurlPause.Recv);
|
61
|
+
}
|
62
|
+
else {
|
63
|
+
reject(new AbortError_js_1.PonyfillAbortError());
|
64
|
+
curlHandle.close();
|
65
|
+
}
|
66
|
+
};
|
67
|
+
}
|
60
68
|
curlHandle.once('end', function endListener() {
|
61
69
|
curlHandle.close();
|
62
70
|
});
|
@@ -90,6 +98,7 @@ function fetchCurl(fetchRequest) {
|
|
90
98
|
headers: headersInit,
|
91
99
|
url: fetchRequest.url,
|
92
100
|
}));
|
101
|
+
streamResolved = true;
|
93
102
|
});
|
94
103
|
curlHandle.perform();
|
95
104
|
});
|
package/esm/fetchCurl.js
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
import { Readable } from 'node:stream';
|
2
|
+
import { PonyfillAbortError } from './AbortError.js';
|
2
3
|
import { PonyfillResponse } from './Response.js';
|
3
4
|
import { defaultHeadersSerializer } from './utils.js';
|
4
5
|
export function fetchCurl(fetchRequest) {
|
5
6
|
const { Curl, CurlCode, CurlFeature, CurlPause, CurlProgressFunc } = globalThis['libcurl'];
|
6
7
|
const curlHandle = new Curl();
|
7
|
-
if (fetchRequest['_signal']) {
|
8
|
-
fetchRequest['_signal'].onabort = () => {
|
9
|
-
curlHandle.pause(CurlPause.Recv);
|
10
|
-
};
|
11
|
-
}
|
12
8
|
curlHandle.enable(CurlFeature.NoDataParsing);
|
13
9
|
curlHandle.setOpt('URL', fetchRequest.url);
|
14
10
|
curlHandle.setOpt('SSL_VERIFYPEER', false);
|
@@ -54,6 +50,18 @@ export function fetchCurl(fetchRequest) {
|
|
54
50
|
curlHandle.setOpt('HTTPHEADER', curlHeaders);
|
55
51
|
curlHandle.enable(CurlFeature.NoHeaderParsing);
|
56
52
|
return new Promise(function promiseResolver(resolve, reject) {
|
53
|
+
let streamResolved = false;
|
54
|
+
if (fetchRequest['_signal']) {
|
55
|
+
fetchRequest['_signal'].onabort = () => {
|
56
|
+
if (streamResolved) {
|
57
|
+
curlHandle.pause(CurlPause.Recv);
|
58
|
+
}
|
59
|
+
else {
|
60
|
+
reject(new PonyfillAbortError());
|
61
|
+
curlHandle.close();
|
62
|
+
}
|
63
|
+
};
|
64
|
+
}
|
57
65
|
curlHandle.once('end', function endListener() {
|
58
66
|
curlHandle.close();
|
59
67
|
});
|
@@ -87,6 +95,7 @@ export function fetchCurl(fetchRequest) {
|
|
87
95
|
headers: headersInit,
|
88
96
|
url: fetchRequest.url,
|
89
97
|
}));
|
98
|
+
streamResolved = true;
|
90
99
|
});
|
91
100
|
curlHandle.perform();
|
92
101
|
});
|