@whatwg-node/node-fetch 0.5.0-alpha-20230531122910-f56e992 → 0.5.0-alpha-20230531142055-c567621
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 +19 -0
- package/esm/fetch.js +19 -0
- package/package.json +1 -1
package/cjs/fetch.js
CHANGED
@@ -27,6 +27,7 @@ exports.fetchPonyfill = void 0;
|
|
27
27
|
const fs_1 = require("fs");
|
28
28
|
const stream_1 = require("stream");
|
29
29
|
const url_1 = require("url");
|
30
|
+
const node_libcurl_1 = require("node-libcurl");
|
30
31
|
const Blob_js_1 = require("./Blob.js");
|
31
32
|
const Headers_js_1 = require("./Headers.js");
|
32
33
|
const Request_js_1 = require("./Request.js");
|
@@ -86,13 +87,28 @@ async function fetchPonyfill(info, init) {
|
|
86
87
|
size = Number(value);
|
87
88
|
}
|
88
89
|
});
|
90
|
+
let easyNativeBinding;
|
91
|
+
fetchRequest.signal.onabort = () => {
|
92
|
+
if (easyNativeBinding != null) {
|
93
|
+
easyNativeBinding.pause(node_libcurl_1.CurlPause.Recv);
|
94
|
+
}
|
95
|
+
};
|
89
96
|
const curlyOptions = {
|
90
97
|
// we want the unparsed binary response to be returned as a stream to us
|
91
98
|
curlyStreamResponse: true,
|
92
99
|
curlyResponseBodyParser: false,
|
100
|
+
curlyProgressCallback() {
|
101
|
+
if (easyNativeBinding == null) {
|
102
|
+
easyNativeBinding = this;
|
103
|
+
}
|
104
|
+
return fetchRequest.signal.aborted ? 1 : 0;
|
105
|
+
},
|
93
106
|
upload: nodeReadable != null,
|
94
107
|
transferEncoding: false,
|
95
108
|
httpTransferDecoding: true,
|
109
|
+
followLocation: fetchRequest.redirect === 'follow',
|
110
|
+
maxRedirs: 20,
|
111
|
+
acceptEncoding: '',
|
96
112
|
curlyStreamUpload: nodeReadable,
|
97
113
|
// this will just make libcurl use their own progress function (which is pretty neat)
|
98
114
|
// curlyProgressCallback() { return CurlProgressFunc.Continue },
|
@@ -108,6 +124,9 @@ async function fetchPonyfill(info, init) {
|
|
108
124
|
const responseHeaders = new Headers_js_1.PonyfillHeaders();
|
109
125
|
curlyResult.headers.forEach(headerInfo => {
|
110
126
|
for (const key in headerInfo) {
|
127
|
+
if (key === 'location' || (key === 'Location' && fetchRequest.redirect === 'error')) {
|
128
|
+
throw new Error('redirects are not allowed');
|
129
|
+
}
|
111
130
|
if (key !== 'result') {
|
112
131
|
responseHeaders.append(key, headerInfo[key]);
|
113
132
|
}
|
package/esm/fetch.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { createReadStream } from 'fs';
|
2
2
|
import { Readable } from 'stream';
|
3
3
|
import { fileURLToPath } from 'url';
|
4
|
+
import { CurlPause } from 'node-libcurl';
|
4
5
|
import { PonyfillBlob } from './Blob.js';
|
5
6
|
import { PonyfillHeaders } from './Headers.js';
|
6
7
|
import { PonyfillRequest } from './Request.js';
|
@@ -60,13 +61,28 @@ export async function fetchPonyfill(info, init) {
|
|
60
61
|
size = Number(value);
|
61
62
|
}
|
62
63
|
});
|
64
|
+
let easyNativeBinding;
|
65
|
+
fetchRequest.signal.onabort = () => {
|
66
|
+
if (easyNativeBinding != null) {
|
67
|
+
easyNativeBinding.pause(CurlPause.Recv);
|
68
|
+
}
|
69
|
+
};
|
63
70
|
const curlyOptions = {
|
64
71
|
// we want the unparsed binary response to be returned as a stream to us
|
65
72
|
curlyStreamResponse: true,
|
66
73
|
curlyResponseBodyParser: false,
|
74
|
+
curlyProgressCallback() {
|
75
|
+
if (easyNativeBinding == null) {
|
76
|
+
easyNativeBinding = this;
|
77
|
+
}
|
78
|
+
return fetchRequest.signal.aborted ? 1 : 0;
|
79
|
+
},
|
67
80
|
upload: nodeReadable != null,
|
68
81
|
transferEncoding: false,
|
69
82
|
httpTransferDecoding: true,
|
83
|
+
followLocation: fetchRequest.redirect === 'follow',
|
84
|
+
maxRedirs: 20,
|
85
|
+
acceptEncoding: '',
|
70
86
|
curlyStreamUpload: nodeReadable,
|
71
87
|
// this will just make libcurl use their own progress function (which is pretty neat)
|
72
88
|
// curlyProgressCallback() { return CurlProgressFunc.Continue },
|
@@ -82,6 +98,9 @@ export async function fetchPonyfill(info, init) {
|
|
82
98
|
const responseHeaders = new PonyfillHeaders();
|
83
99
|
curlyResult.headers.forEach(headerInfo => {
|
84
100
|
for (const key in headerInfo) {
|
101
|
+
if (key === 'location' || (key === 'Location' && fetchRequest.redirect === 'error')) {
|
102
|
+
throw new Error('redirects are not allowed');
|
103
|
+
}
|
85
104
|
if (key !== 'result') {
|
86
105
|
responseHeaders.append(key, headerInfo[key]);
|
87
106
|
}
|