rekwest 2.3.5 → 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/helpers.js +3 -7
- package/dist/index.js +25 -9
- package/package.json +1 -1
- package/src/helpers.mjs +1 -4
- package/src/index.mjs +7 -2
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
|
|
|
@@ -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
|
|
package/dist/index.js
CHANGED
|
@@ -7,11 +7,13 @@ 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
|
+
|
|
16
|
+
var _https = _interopRequireDefault(require("https"));
|
|
15
17
|
|
|
16
18
|
var _ackn = require("./ackn.js");
|
|
17
19
|
|
|
@@ -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
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,
|
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
|
});
|