@e-mc/request 0.9.9 → 0.10.1
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/README.md +7 -4
- package/http/host/index.js +38 -9
- package/index.js +833 -667
- package/package.json +3 -3
- package/util.d.ts +2 -0
- package/util.js +51 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Request constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"license": "BSD 3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/module": "0.
|
|
24
|
-
"@e-mc/types": "0.
|
|
23
|
+
"@e-mc/module": "0.10.1",
|
|
24
|
+
"@e-mc/types": "0.10.1",
|
|
25
25
|
"combined-stream": "^1.0.8",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"picomatch": "^4.0.2",
|
package/util.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AuthValue } from '../types/lib/http';
|
|
2
|
+
import type { HttpProxySettings } from '../types/lib/settings';
|
|
2
3
|
|
|
3
4
|
import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
|
|
4
5
|
import type { Readable, Writable } from 'stream';
|
|
@@ -11,6 +12,7 @@ declare namespace util {
|
|
|
11
12
|
function hasBasicAuth(value: string): boolean;
|
|
12
13
|
function checkRetryable(err: unknown): boolean;
|
|
13
14
|
function isRetryable(value: number, timeout?: boolean): boolean;
|
|
15
|
+
function parseHttpProxy(value?: string): HttpProxySettings | undefined;
|
|
14
16
|
function trimPath(value: string): string;
|
|
15
17
|
function asInt(value: unknown): number;
|
|
16
18
|
function asFloat(value: unknown): number;
|
package/util.js
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports.
|
|
2
|
+
exports.parseHeader = parseHeader;
|
|
3
|
+
exports.normalizeHeaders = normalizeHeaders;
|
|
4
|
+
exports.getBasicAuth = getBasicAuth;
|
|
5
|
+
exports.hasBasicAuth = hasBasicAuth;
|
|
6
|
+
exports.checkRetryable = checkRetryable;
|
|
7
|
+
exports.isRetryable = isRetryable;
|
|
8
|
+
exports.parseHttpProxy = parseHttpProxy;
|
|
9
|
+
exports.trimPath = trimPath;
|
|
10
|
+
exports.asInt = asInt;
|
|
11
|
+
exports.asFloat = asFloat;
|
|
12
|
+
exports.fromSeconds = fromSeconds;
|
|
13
|
+
exports.getTransferRate = getTransferRate;
|
|
14
|
+
exports.hasSize = hasSize;
|
|
15
|
+
exports.getSize = getSize;
|
|
16
|
+
exports.hasSameStat = hasSameStat;
|
|
17
|
+
exports.byteLength = byteLength;
|
|
18
|
+
exports.cleanupStream = cleanupStream;
|
|
3
19
|
const path = require("path");
|
|
4
|
-
const util = require("util");
|
|
5
20
|
const fs = require("fs");
|
|
21
|
+
const util = require("util");
|
|
6
22
|
const module_1 = require("@e-mc/module");
|
|
7
23
|
const types_1 = require("@e-mc/types");
|
|
8
|
-
const SUPPORTED_USVSTRING =
|
|
24
|
+
const SUPPORTED_USVSTRING = (0, types_1.supported)(16, 8);
|
|
9
25
|
const safeInt = (value) => value >= 0 ? Math.min(value, Number.MAX_SAFE_INTEGER) : NaN;
|
|
10
26
|
function parseHeader(headers, name) {
|
|
11
27
|
const value = headers[name];
|
|
@@ -24,7 +40,6 @@ function parseHeader(headers, name) {
|
|
|
24
40
|
}
|
|
25
41
|
}
|
|
26
42
|
}
|
|
27
|
-
exports.parseHeader = parseHeader;
|
|
28
43
|
function normalizeHeaders(headers) {
|
|
29
44
|
const result = Object.create(null);
|
|
30
45
|
for (const name in headers) {
|
|
@@ -49,14 +64,12 @@ function normalizeHeaders(headers) {
|
|
|
49
64
|
}
|
|
50
65
|
return result;
|
|
51
66
|
}
|
|
52
|
-
exports.normalizeHeaders = normalizeHeaders;
|
|
53
67
|
function getBasicAuth(username, password) {
|
|
54
68
|
if ((0, types_1.isObject)(username)) {
|
|
55
69
|
({ username, password } = username);
|
|
56
70
|
}
|
|
57
71
|
return (0, types_1.isString)(username) ? encodeURIComponent(SUPPORTED_USVSTRING ? util.toUSVString(username) : username) + ((0, types_1.isString)(password) ? ':' + encodeURIComponent(SUPPORTED_USVSTRING ? util.toUSVString(password) : password) : '') + '@' : '';
|
|
58
72
|
}
|
|
59
|
-
exports.getBasicAuth = getBasicAuth;
|
|
60
73
|
function hasBasicAuth(value) {
|
|
61
74
|
try {
|
|
62
75
|
return new URL(value).username.length > 0;
|
|
@@ -65,7 +78,6 @@ function hasBasicAuth(value) {
|
|
|
65
78
|
}
|
|
66
79
|
return false;
|
|
67
80
|
}
|
|
68
|
-
exports.hasBasicAuth = hasBasicAuth;
|
|
69
81
|
function checkRetryable(err) {
|
|
70
82
|
if (err instanceof Error) {
|
|
71
83
|
const { code, errno } = err;
|
|
@@ -86,7 +98,6 @@ function checkRetryable(err) {
|
|
|
86
98
|
}
|
|
87
99
|
return false;
|
|
88
100
|
}
|
|
89
|
-
exports.checkRetryable = checkRetryable;
|
|
90
101
|
function isRetryable(value, timeout) {
|
|
91
102
|
switch (value) {
|
|
92
103
|
case 408:
|
|
@@ -109,12 +120,42 @@ function isRetryable(value, timeout) {
|
|
|
109
120
|
return false;
|
|
110
121
|
}
|
|
111
122
|
}
|
|
112
|
-
|
|
123
|
+
function parseHttpProxy(value) {
|
|
124
|
+
value || (value = process.env.HTTP_PROXY || process.env.HTTPS_PROXY);
|
|
125
|
+
if (value) {
|
|
126
|
+
try {
|
|
127
|
+
const url = new URL(value);
|
|
128
|
+
if (url.port) {
|
|
129
|
+
let exclude;
|
|
130
|
+
if (process.env.NO_PROXY) {
|
|
131
|
+
exclude = [];
|
|
132
|
+
for (const item of process.env.NO_PROXY.trim().split(/\s*,\s*/)) {
|
|
133
|
+
if (module_1.isURL(item)) {
|
|
134
|
+
exclude.push(item);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
exclude.push(`https://${item}`, `http://${item}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
address: url.protocol + '//' + url.hostname,
|
|
143
|
+
port: url.port,
|
|
144
|
+
origin: url.origin,
|
|
145
|
+
username: url.username ? decodeURIComponent(url.username) : '',
|
|
146
|
+
password: url.password ? decodeURIComponent(url.password) : '',
|
|
147
|
+
exclude
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
113
155
|
function trimPath(value) {
|
|
114
156
|
const length = value.length - 1;
|
|
115
157
|
return value[length] === '/' ? value.substring(0, length) : value;
|
|
116
158
|
}
|
|
117
|
-
exports.trimPath = trimPath;
|
|
118
159
|
function asInt(value) {
|
|
119
160
|
switch (typeof value) {
|
|
120
161
|
case 'string':
|
|
@@ -125,7 +166,6 @@ function asInt(value) {
|
|
|
125
166
|
return NaN;
|
|
126
167
|
}
|
|
127
168
|
}
|
|
128
|
-
exports.asInt = asInt;
|
|
129
169
|
function asFloat(value) {
|
|
130
170
|
switch (typeof value) {
|
|
131
171
|
case 'string':
|
|
@@ -136,7 +176,6 @@ function asFloat(value) {
|
|
|
136
176
|
return NaN;
|
|
137
177
|
}
|
|
138
178
|
}
|
|
139
|
-
exports.asFloat = asFloat;
|
|
140
179
|
function fromSeconds(value) {
|
|
141
180
|
switch (typeof value) {
|
|
142
181
|
case 'string':
|
|
@@ -147,7 +186,6 @@ function fromSeconds(value) {
|
|
|
147
186
|
return NaN;
|
|
148
187
|
}
|
|
149
188
|
}
|
|
150
|
-
exports.fromSeconds = fromSeconds;
|
|
151
189
|
function getTransferRate(length, timeMs, unitSeparator = '') {
|
|
152
190
|
const unit = (length * 8) / timeMs;
|
|
153
191
|
if (unit < 1) {
|
|
@@ -158,7 +196,6 @@ function getTransferRate(length, timeMs, unitSeparator = '') {
|
|
|
158
196
|
}
|
|
159
197
|
return (unit / 1000).toPrecision(3) + unitSeparator + 'GiB/s';
|
|
160
198
|
}
|
|
161
|
-
exports.getTransferRate = getTransferRate;
|
|
162
199
|
function hasSize(value, keepEmpty) {
|
|
163
200
|
try {
|
|
164
201
|
const statSrc = fs.statSync(value);
|
|
@@ -173,7 +210,6 @@ function hasSize(value, keepEmpty) {
|
|
|
173
210
|
}
|
|
174
211
|
return false;
|
|
175
212
|
}
|
|
176
|
-
exports.hasSize = hasSize;
|
|
177
213
|
function getSize(value, diskUsed) {
|
|
178
214
|
try {
|
|
179
215
|
return (diskUsed ? fs.lstatSync(value) : fs.statSync(value)).size;
|
|
@@ -182,7 +218,6 @@ function getSize(value, diskUsed) {
|
|
|
182
218
|
return 0;
|
|
183
219
|
}
|
|
184
220
|
}
|
|
185
|
-
exports.getSize = getSize;
|
|
186
221
|
function hasSameStat(src, dest, keepEmpty) {
|
|
187
222
|
try {
|
|
188
223
|
if (fs.existsSync(dest)) {
|
|
@@ -200,11 +235,9 @@ function hasSameStat(src, dest, keepEmpty) {
|
|
|
200
235
|
}
|
|
201
236
|
return false;
|
|
202
237
|
}
|
|
203
|
-
exports.hasSameStat = hasSameStat;
|
|
204
238
|
function byteLength(value, encoding) {
|
|
205
239
|
return typeof value === 'string' && (path.isAbsolute(value) || module_1.isPath(value)) ? getSize(value) : Buffer.byteLength(value, encoding && (0, types_1.getEncoding)(encoding));
|
|
206
240
|
}
|
|
207
|
-
exports.byteLength = byteLength;
|
|
208
241
|
function cleanupStream(stream, uri) {
|
|
209
242
|
try {
|
|
210
243
|
stream.removeAllListeners();
|
|
@@ -219,4 +252,3 @@ function cleanupStream(stream, uri) {
|
|
|
219
252
|
}
|
|
220
253
|
}
|
|
221
254
|
}
|
|
222
|
-
exports.cleanupStream = cleanupStream;
|