rekwest 2.3.2 → 2.3.6
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/dist/formdata.js +3 -3
- package/dist/helpers.js +18 -27
- package/dist/index.js +32 -16
- package/package.json +6 -6
- package/src/helpers.mjs +16 -25
- package/src/index.mjs +7 -2
package/dist/formdata.js
CHANGED
|
@@ -9,11 +9,11 @@ var _http = _interopRequireDefault(require("http2"));
|
|
|
9
9
|
|
|
10
10
|
var _util = require("util");
|
|
11
11
|
|
|
12
|
-
var _file = require("./file.
|
|
12
|
+
var _file = require("./file.js");
|
|
13
13
|
|
|
14
|
-
var _helpers = require("./helpers.
|
|
14
|
+
var _helpers = require("./helpers.js");
|
|
15
15
|
|
|
16
|
-
var _mediatypes = require("./mediatypes.
|
|
16
|
+
var _mediatypes = require("./mediatypes.js");
|
|
17
17
|
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
19
|
|
package/dist/helpers.js
CHANGED
|
@@ -7,9 +7,7 @@ exports.transform = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _buffer = require("buffer");
|
|
9
9
|
|
|
10
|
-
var _http = require("
|
|
11
|
-
|
|
12
|
-
var _http2 = _interopRequireDefault(require("http2"));
|
|
10
|
+
var _http = _interopRequireDefault(require("http2"));
|
|
13
11
|
|
|
14
12
|
var _stream = require("stream");
|
|
15
13
|
|
|
@@ -17,13 +15,13 @@ var _util = require("util");
|
|
|
17
15
|
|
|
18
16
|
var _zlib = _interopRequireDefault(require("zlib"));
|
|
19
17
|
|
|
20
|
-
var _cookies = require("./cookies.
|
|
18
|
+
var _cookies = require("./cookies.js");
|
|
21
19
|
|
|
22
|
-
var _file = require("./file.
|
|
20
|
+
var _file = require("./file.js");
|
|
23
21
|
|
|
24
|
-
var _formdata = require("./formdata.
|
|
22
|
+
var _formdata = require("./formdata.js");
|
|
25
23
|
|
|
26
|
-
var _mediatypes = require("./mediatypes.
|
|
24
|
+
var _mediatypes = require("./mediatypes.js");
|
|
27
25
|
|
|
28
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
27
|
|
|
@@ -40,7 +38,7 @@ const {
|
|
|
40
38
|
HTTP2_HEADER_SCHEME,
|
|
41
39
|
HTTP2_METHOD_GET,
|
|
42
40
|
HTTP2_METHOD_HEAD
|
|
43
|
-
} =
|
|
41
|
+
} = _http.default.constants;
|
|
44
42
|
const brotliCompress = (0, _util.promisify)(_zlib.default.brotliCompress);
|
|
45
43
|
const brotliDecompress = (0, _util.promisify)(_zlib.default.brotliDecompress);
|
|
46
44
|
const gzip = (0, _util.promisify)(_zlib.default.gzip);
|
|
@@ -139,9 +137,7 @@ const preflight = options => {
|
|
|
139
137
|
redirected
|
|
140
138
|
} = options;
|
|
141
139
|
|
|
142
|
-
if (
|
|
143
|
-
options.agent ??= url.protocol === 'http:' ? _http.globalAgent : void 0;
|
|
144
|
-
} else {
|
|
140
|
+
if (h2) {
|
|
145
141
|
options.endStream = [HTTP2_METHOD_GET, HTTP2_METHOD_HEAD].includes(method);
|
|
146
142
|
}
|
|
147
143
|
|
|
@@ -199,36 +195,31 @@ const premix = (res, {
|
|
|
199
195
|
Object.defineProperties(res, {
|
|
200
196
|
arrayBuffer: {
|
|
201
197
|
enumerable: true,
|
|
202
|
-
value:
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const {
|
|
198
|
+
value: function () {
|
|
199
|
+
parse &&= false;
|
|
200
|
+
return this.body().then(({
|
|
206
201
|
buffer,
|
|
207
202
|
byteLength,
|
|
208
203
|
byteOffset
|
|
209
|
-
}
|
|
210
|
-
return buffer.slice(byteOffset, byteOffset + byteLength);
|
|
204
|
+
}) => buffer.slice(byteOffset, byteOffset + byteLength));
|
|
211
205
|
}
|
|
212
206
|
},
|
|
213
207
|
blob: {
|
|
214
208
|
enumerable: true,
|
|
215
|
-
value:
|
|
216
|
-
|
|
217
|
-
return new _buffer.Blob([val]);
|
|
209
|
+
value: function () {
|
|
210
|
+
return this.arrayBuffer().then(res => new _buffer.Blob([res]));
|
|
218
211
|
}
|
|
219
212
|
},
|
|
220
213
|
json: {
|
|
221
214
|
enumerable: true,
|
|
222
|
-
value:
|
|
223
|
-
|
|
224
|
-
return JSON.parse(val);
|
|
215
|
+
value: function () {
|
|
216
|
+
return this.text().then(res => JSON.parse(res));
|
|
225
217
|
}
|
|
226
218
|
},
|
|
227
219
|
text: {
|
|
228
220
|
enumerable: true,
|
|
229
|
-
value:
|
|
230
|
-
|
|
231
|
-
return val.toString();
|
|
221
|
+
value: function () {
|
|
222
|
+
return this.blob().then(blob => blob.text());
|
|
232
223
|
}
|
|
233
224
|
}
|
|
234
225
|
});
|
|
@@ -258,7 +249,7 @@ const premix = (res, {
|
|
|
258
249
|
|
|
259
250
|
if (spool.length && parse) {
|
|
260
251
|
const contentType = this.headers[HTTP2_HEADER_CONTENT_TYPE] ?? '';
|
|
261
|
-
const charset = contentType.split(';').find(it => /charset=/i.test(it))?.toLowerCase()
|
|
252
|
+
const charset = contentType.split(';').find(it => /charset=/i.test(it))?.toLowerCase().replace('charset=', '').replace('iso-8859-1', 'latin1').trim() || 'utf-8';
|
|
262
253
|
|
|
263
254
|
if (/\bjson\b/i.test(contentType)) {
|
|
264
255
|
spool = JSON.parse(spool.toString(charset));
|
package/dist/index.js
CHANGED
|
@@ -7,13 +7,15 @@ var _exportNames = {
|
|
|
7
7
|
exports.constants = void 0;
|
|
8
8
|
exports.default = rekwest;
|
|
9
9
|
|
|
10
|
-
var _http = _interopRequireDefault(require("
|
|
10
|
+
var _http = _interopRequireDefault(require("http"));
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
var _http2 = _interopRequireDefault(require("http2"));
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
exports.constants = _http2.constants;
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _https = _interopRequireDefault(require("https"));
|
|
17
|
+
|
|
18
|
+
var _ackn = require("./ackn.js");
|
|
17
19
|
|
|
18
20
|
Object.keys(_ackn).forEach(function (key) {
|
|
19
21
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -22,7 +24,7 @@ Object.keys(_ackn).forEach(function (key) {
|
|
|
22
24
|
exports[key] = _ackn[key];
|
|
23
25
|
});
|
|
24
26
|
|
|
25
|
-
var _cookies = require("./cookies.
|
|
27
|
+
var _cookies = require("./cookies.js");
|
|
26
28
|
|
|
27
29
|
Object.keys(_cookies).forEach(function (key) {
|
|
28
30
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -31,7 +33,7 @@ Object.keys(_cookies).forEach(function (key) {
|
|
|
31
33
|
exports[key] = _cookies[key];
|
|
32
34
|
});
|
|
33
35
|
|
|
34
|
-
var _errors = require("./errors.
|
|
36
|
+
var _errors = require("./errors.js");
|
|
35
37
|
|
|
36
38
|
Object.keys(_errors).forEach(function (key) {
|
|
37
39
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -40,7 +42,7 @@ Object.keys(_errors).forEach(function (key) {
|
|
|
40
42
|
exports[key] = _errors[key];
|
|
41
43
|
});
|
|
42
44
|
|
|
43
|
-
var _helpers = require("./helpers.
|
|
45
|
+
var _helpers = require("./helpers.js");
|
|
44
46
|
|
|
45
47
|
Object.keys(_helpers).forEach(function (key) {
|
|
46
48
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -49,9 +51,9 @@ Object.keys(_helpers).forEach(function (key) {
|
|
|
49
51
|
exports[key] = _helpers[key];
|
|
50
52
|
});
|
|
51
53
|
|
|
52
|
-
var _mediatypes = require("./mediatypes.
|
|
54
|
+
var _mediatypes = require("./mediatypes.js");
|
|
53
55
|
|
|
54
|
-
var _file = require("./file.
|
|
56
|
+
var _file = require("./file.js");
|
|
55
57
|
|
|
56
58
|
Object.keys(_file).forEach(function (key) {
|
|
57
59
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -60,7 +62,7 @@ Object.keys(_file).forEach(function (key) {
|
|
|
60
62
|
exports[key] = _file[key];
|
|
61
63
|
});
|
|
62
64
|
|
|
63
|
-
var _formdata = require("./formdata.
|
|
65
|
+
var _formdata = require("./formdata.js");
|
|
64
66
|
|
|
65
67
|
Object.keys(_formdata).forEach(function (key) {
|
|
66
68
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -81,7 +83,7 @@ const {
|
|
|
81
83
|
HTTP2_METHOD_HEAD,
|
|
82
84
|
HTTP_STATUS_BAD_REQUEST,
|
|
83
85
|
HTTP_STATUS_SEE_OTHER
|
|
84
|
-
} =
|
|
86
|
+
} = _http2.default.constants;
|
|
85
87
|
|
|
86
88
|
async function rekwest(url, options = {}) {
|
|
87
89
|
url = options.url = new URL(url);
|
|
@@ -115,8 +117,14 @@ async function rekwest(url, options = {}) {
|
|
|
115
117
|
h2,
|
|
116
118
|
redirect,
|
|
117
119
|
redirected,
|
|
118
|
-
thenable
|
|
120
|
+
thenable,
|
|
121
|
+
url: {
|
|
122
|
+
protocol
|
|
123
|
+
}
|
|
119
124
|
} = options;
|
|
125
|
+
const {
|
|
126
|
+
request
|
|
127
|
+
} = protocol === 'http:' ? _http.default : _https.default;
|
|
120
128
|
let {
|
|
121
129
|
body
|
|
122
130
|
} = options;
|
|
@@ -125,10 +133,10 @@ async function rekwest(url, options = {}) {
|
|
|
125
133
|
body &&= (0, _helpers.transform)(body, options);
|
|
126
134
|
|
|
127
135
|
if (h2) {
|
|
128
|
-
client =
|
|
136
|
+
client = _http2.default.connect(url.origin, options);
|
|
129
137
|
req = client.request(options.headers, options);
|
|
130
138
|
} else {
|
|
131
|
-
req =
|
|
139
|
+
req = request(url, options);
|
|
132
140
|
}
|
|
133
141
|
|
|
134
142
|
req.on('response', res => {
|
|
@@ -258,7 +266,7 @@ Reflect.defineProperty(rekwest, 'stream', {
|
|
|
258
266
|
});
|
|
259
267
|
|
|
260
268
|
if (options.h2) {
|
|
261
|
-
const client =
|
|
269
|
+
const client = _http2.default.connect(url.origin, options);
|
|
262
270
|
|
|
263
271
|
const req = client.request(options.headers, options);
|
|
264
272
|
req.on('end', () => {
|
|
@@ -267,7 +275,15 @@ Reflect.defineProperty(rekwest, 'stream', {
|
|
|
267
275
|
return req;
|
|
268
276
|
}
|
|
269
277
|
|
|
270
|
-
|
|
278
|
+
const {
|
|
279
|
+
url: {
|
|
280
|
+
protocol
|
|
281
|
+
}
|
|
282
|
+
} = options;
|
|
283
|
+
const {
|
|
284
|
+
request
|
|
285
|
+
} = protocol === 'http:' ? _http.default : _https.default;
|
|
286
|
+
return request(options.url, options);
|
|
271
287
|
}
|
|
272
288
|
});
|
|
273
289
|
Reflect.defineProperty(rekwest, 'defaults', {
|
package/package.json
CHANGED
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@babel/cli": "^7.16.8",
|
|
12
|
-
"@babel/core": "^7.16.
|
|
12
|
+
"@babel/core": "^7.16.12",
|
|
13
13
|
"@babel/eslint-parser": "^7.16.5",
|
|
14
|
-
"@babel/preset-env": "^7.16.
|
|
14
|
+
"@babel/preset-env": "^7.16.11",
|
|
15
15
|
"c8": "^7.11.0",
|
|
16
|
-
"eslint": "^8.
|
|
16
|
+
"eslint": "^8.7.0",
|
|
17
17
|
"eslint-config-ultra-refined": "^2.3.0",
|
|
18
|
-
"mocha": "^9.
|
|
18
|
+
"mocha": "^9.2.0"
|
|
19
19
|
},
|
|
20
20
|
"description": "The robust request library that humanity deserves 🌐",
|
|
21
21
|
"engines": {
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"cert:gen": "openssl req -days 365 -keyout localhost.key -newkey ec -nodes -pkeyopt ec_paramgen_curve:prime256v1 -subj //SKIP=1/CN=localhost -out localhost.cert -x509",
|
|
55
55
|
"cert:ken": "openssl x509 -in localhost.cert -noout -text",
|
|
56
56
|
"lint": "eslint . --ext .cjs,.js,.mjs",
|
|
57
|
-
"prepack": "npm run build",
|
|
57
|
+
"prepack": "npm run build && sh pony.sh",
|
|
58
58
|
"pretest": "rm -rf coverage && npm run cert:gen",
|
|
59
59
|
"test": "mocha --exit --recursive",
|
|
60
60
|
"test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
|
|
61
61
|
},
|
|
62
|
-
"version": "2.3.
|
|
62
|
+
"version": "2.3.6"
|
|
63
63
|
}
|
package/src/helpers.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Blob } from 'buffer';
|
|
2
|
-
import { globalAgent } from 'http';
|
|
3
2
|
import http2 from 'http2';
|
|
4
3
|
import {
|
|
5
4
|
PassThrough,
|
|
@@ -123,9 +122,7 @@ export const preflight = (options) => {
|
|
|
123
122
|
const url = options.url = new URL(options.url);
|
|
124
123
|
const { cookies, h2 = false, method = HTTP2_METHOD_GET, headers, redirected } = options;
|
|
125
124
|
|
|
126
|
-
if (
|
|
127
|
-
options.agent ??= url.protocol === 'http:' ? globalAgent : void 0;
|
|
128
|
-
} else {
|
|
125
|
+
if (h2) {
|
|
129
126
|
options.endStream = [
|
|
130
127
|
HTTP2_METHOD_GET,
|
|
131
128
|
HTTP2_METHOD_HEAD,
|
|
@@ -182,37 +179,31 @@ export const premix = (res, { digest = false, parse = false } = {}) => {
|
|
|
182
179
|
Object.defineProperties(res, {
|
|
183
180
|
arrayBuffer: {
|
|
184
181
|
enumerable: true,
|
|
185
|
-
value:
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
parse = false;
|
|
189
|
-
const { buffer, byteLength, byteOffset } = await this.body().finally(() => parse = stash);
|
|
182
|
+
value: function () {
|
|
183
|
+
parse &&= false;
|
|
190
184
|
|
|
191
|
-
return
|
|
185
|
+
return this.body().then(({ buffer, byteLength, byteOffset }) => buffer.slice(
|
|
186
|
+
byteOffset,
|
|
187
|
+
byteOffset + byteLength,
|
|
188
|
+
));
|
|
192
189
|
},
|
|
193
190
|
},
|
|
194
191
|
blob: {
|
|
195
192
|
enumerable: true,
|
|
196
|
-
value:
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return new Blob([val]);
|
|
193
|
+
value: function () {
|
|
194
|
+
return this.arrayBuffer().then((res) => new Blob([res]));
|
|
200
195
|
},
|
|
201
196
|
},
|
|
202
197
|
json: {
|
|
203
198
|
enumerable: true,
|
|
204
|
-
value:
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
return JSON.parse(val);
|
|
199
|
+
value: function () {
|
|
200
|
+
return this.text().then((res) => JSON.parse(res));
|
|
208
201
|
},
|
|
209
202
|
},
|
|
210
203
|
text: {
|
|
211
204
|
enumerable: true,
|
|
212
|
-
value:
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return val.toString();
|
|
205
|
+
value: function () {
|
|
206
|
+
return this.blob().then((blob) => blob.text());
|
|
216
207
|
},
|
|
217
208
|
},
|
|
218
209
|
});
|
|
@@ -243,9 +234,9 @@ export const premix = (res, { digest = false, parse = false } = {}) => {
|
|
|
243
234
|
const charset = contentType.split(';')
|
|
244
235
|
.find((it) => /charset=/i.test(it))
|
|
245
236
|
?.toLowerCase()
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
237
|
+
.replace('charset=', '')
|
|
238
|
+
.replace('iso-8859-1', 'latin1')
|
|
239
|
+
.trim() || 'utf-8';
|
|
249
240
|
|
|
250
241
|
if (/\bjson\b/i.test(contentType)) {
|
|
251
242
|
spool = JSON.parse(spool.toString(charset));
|
package/src/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import http from 'http';
|
|
1
2
|
import http2 from 'http2';
|
|
2
|
-
import
|
|
3
|
+
import https from 'https';
|
|
3
4
|
import { ackn } from './ackn.mjs';
|
|
4
5
|
import { Cookies } from './cookies.mjs';
|
|
5
6
|
import { RequestError } from './errors.mjs';
|
|
@@ -63,7 +64,8 @@ export default async function rekwest(url, options = {}) {
|
|
|
63
64
|
|
|
64
65
|
options = preflight(options);
|
|
65
66
|
|
|
66
|
-
const { cookies, digest, follow, h2, redirect, redirected, thenable } = options;
|
|
67
|
+
const { cookies, digest, follow, h2, redirect, redirected, thenable, url: { protocol } } = options;
|
|
68
|
+
const { request } = (protocol === 'http:' ? http : https);
|
|
67
69
|
let { body } = options;
|
|
68
70
|
|
|
69
71
|
const promise = new Promise((resolve, reject) => {
|
|
@@ -222,6 +224,9 @@ Reflect.defineProperty(rekwest, 'stream', {
|
|
|
222
224
|
return req;
|
|
223
225
|
}
|
|
224
226
|
|
|
227
|
+
const { url: { protocol } } = options;
|
|
228
|
+
const { request } = (protocol === 'http:' ? http : https);
|
|
229
|
+
|
|
225
230
|
return request(options.url, options);
|
|
226
231
|
},
|
|
227
232
|
});
|