@e-mc/request 0.12.2 → 0.12.4
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 +8 -6
- package/http/adapter/index.js +5 -0
- package/index.js +15 -11
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.12.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.12.4/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IModule, ModuleConstructor } from "./index";
|
|
@@ -42,8 +42,8 @@ interface IRequest extends IModule {
|
|
|
42
42
|
headersOf(uri: string): OutgoingHttpHeaders | undefined;
|
|
43
43
|
aria2c(uri: string | URL, pathname: string): Promise<string[]>;
|
|
44
44
|
aria2c(uri: string | URL, options?: Aria2Options): Promise<string[]>;
|
|
45
|
-
rclone(uri: string, pathname: string): Promise<string[]>;
|
|
46
|
-
rclone(uri: string, options?: RcloneOptions): Promise<string[]>;
|
|
45
|
+
rclone(uri: string | URL, pathname: string): Promise<string[]>;
|
|
46
|
+
rclone(uri: string | URL, options?: RcloneOptions): Promise<string[]>;
|
|
47
47
|
json(uri: string | URL, options?: OpenOptions): Promise<object | null>;
|
|
48
48
|
pipe(uri: string | URL, to: Writable, options?: OpenOptions): Promise<null>;
|
|
49
49
|
opts(url: string | URL, options?: OpenOptions): HostConfig;
|
|
@@ -81,7 +81,9 @@ interface RequestConstructor extends ModuleConstructor {
|
|
|
81
81
|
defineHttpAgent(options: HttpAgentSettings): void;
|
|
82
82
|
defineDnsLookup(options: DnsLookupSettings, clear?: boolean): void;
|
|
83
83
|
defineHttpAdapter(module: unknown): void;
|
|
84
|
+
isRclone(value: string | URL): boolean;
|
|
84
85
|
getAria2Path(): string;
|
|
86
|
+
getRclonePath(): string;
|
|
85
87
|
readonly prototype: IRequest;
|
|
86
88
|
new(module?: RequestModule): IRequest;
|
|
87
89
|
}
|
|
@@ -253,9 +255,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
|
|
|
253
255
|
|
|
254
256
|
## References
|
|
255
257
|
|
|
256
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
257
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
258
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
258
|
+
- https://www.unpkg.com/@e-mc/types@0.12.4/lib/http.d.ts
|
|
259
|
+
- https://www.unpkg.com/@e-mc/types@0.12.4/lib/request.d.ts
|
|
260
|
+
- https://www.unpkg.com/@e-mc/types@0.12.4/lib/settings.d.ts
|
|
259
261
|
|
|
260
262
|
* https://www.npmjs.com/package/@types/node
|
|
261
263
|
|
package/http/adapter/index.js
CHANGED
|
@@ -298,6 +298,11 @@ class HttpAdapter {
|
|
|
298
298
|
}
|
|
299
299
|
});
|
|
300
300
|
}
|
|
301
|
+
if (opts.trailers) {
|
|
302
|
+
this.client.once('trailers', (trailers) => {
|
|
303
|
+
opts.trailers.call(this.client, trailers);
|
|
304
|
+
});
|
|
305
|
+
}
|
|
301
306
|
this.client.once('end', () => {
|
|
302
307
|
if (this.closed || this.aborted) {
|
|
303
308
|
return;
|
package/index.js
CHANGED
|
@@ -24,6 +24,7 @@ const SUPPORTED_NODE20 = (0, types_1.supported)(20);
|
|
|
24
24
|
const SUPPORTED_ZSTD = (0, types_1.supported)(23, 8) && typeof zlib.createZstdDecompress === 'function';
|
|
25
25
|
const REGEXP_PEMCERT = /^-{3,}[ \t]*BEGIN[ \t].+\n-{3,}[ \t]*END[ \t][^-]+-{3,}$/s;
|
|
26
26
|
const REGEXP_GLOBWITHIN = /\\\?|(?:(?<!\\)(?:\*|\[!?[^!\]]+\]|\{(?:[^,]+,)+[^}]+\}|[!?+*@]\((?:[^|]+\|)*[^)]+\)|\?.*\?|\?$))/;
|
|
27
|
+
const REGEXP_RCLONE = /^rclone:\?/i;
|
|
27
28
|
const HTTP = {
|
|
28
29
|
HOST: {},
|
|
29
30
|
HEADERS: {},
|
|
@@ -390,7 +391,7 @@ function setBinExec(settings, target) {
|
|
|
390
391
|
target.EXEC_GID = (gid = (0, util_1.asInt)(gid)) >= 0 ? gid : undefined;
|
|
391
392
|
}
|
|
392
393
|
}
|
|
393
|
-
function parseBinOpts(instance, options, ignore, skip) {
|
|
394
|
+
function parseBinOpts(instance, options, ignore, skip, doubleQuote) {
|
|
394
395
|
let pathname = options.pathname, binOpts;
|
|
395
396
|
if (!(0, types_1.isString)(pathname)) {
|
|
396
397
|
if (!instance.host) {
|
|
@@ -427,12 +428,12 @@ function parseBinOpts(instance, options, ignore, skip) {
|
|
|
427
428
|
case '--help':
|
|
428
429
|
return [];
|
|
429
430
|
default:
|
|
430
|
-
return match[3] ? [match[1] + '=' + (0, types_1.sanitizeArgs)(match[3])] : [match[1]];
|
|
431
|
+
return match[3] ? [match[1] + '=' + (0, types_1.sanitizeArgs)(match[3], doubleQuote)] : [match[1]];
|
|
431
432
|
}
|
|
432
433
|
}
|
|
433
434
|
}
|
|
434
435
|
else if (value) {
|
|
435
|
-
return [(0, types_1.sanitizeArgs)(value)];
|
|
436
|
+
return [(0, types_1.sanitizeArgs)(value, doubleQuote)];
|
|
436
437
|
}
|
|
437
438
|
break;
|
|
438
439
|
}
|
|
@@ -441,7 +442,7 @@ function parseBinOpts(instance, options, ignore, skip) {
|
|
|
441
442
|
return [opt.toString()];
|
|
442
443
|
default:
|
|
443
444
|
if ((0, types_1.isArray)(opt)) {
|
|
444
|
-
return opt.filter(item => (0, types_1.isString)(item)).map(item => (0, types_1.sanitizeArgs)(item));
|
|
445
|
+
return opt.filter(item => (0, types_1.isString)(item)).map(item => (0, types_1.sanitizeArgs)(item, doubleQuote));
|
|
445
446
|
}
|
|
446
447
|
break;
|
|
447
448
|
}
|
|
@@ -872,6 +873,9 @@ class Request extends module_1 {
|
|
|
872
873
|
HTTP_ADAPTER = module;
|
|
873
874
|
}
|
|
874
875
|
}
|
|
876
|
+
static isRclone(value) {
|
|
877
|
+
return REGEXP_RCLONE.test(value.toString());
|
|
878
|
+
}
|
|
875
879
|
static getAria2Path() {
|
|
876
880
|
return ARIA2.BIN;
|
|
877
881
|
}
|
|
@@ -900,7 +904,6 @@ class Request extends module_1 {
|
|
|
900
904
|
#ipVersion;
|
|
901
905
|
#agentTimeout;
|
|
902
906
|
#headers = null;
|
|
903
|
-
#certs = null;
|
|
904
907
|
#baseUrl = null;
|
|
905
908
|
#connectDns = Object.create(null);
|
|
906
909
|
#pendingDns = Object.create(null);
|
|
@@ -908,6 +911,7 @@ class Request extends module_1 {
|
|
|
908
911
|
#statusOn = null;
|
|
909
912
|
#headersOn = null;
|
|
910
913
|
#adapter = HTTP_ADAPTER;
|
|
914
|
+
#certs = null;
|
|
911
915
|
#downloading = new Set();
|
|
912
916
|
#hostInfo = {};
|
|
913
917
|
#session = [Object.create(null)];
|
|
@@ -1280,7 +1284,7 @@ class Request extends module_1 {
|
|
|
1280
1284
|
}
|
|
1281
1285
|
else {
|
|
1282
1286
|
({ signal, silent } = options);
|
|
1283
|
-
[pathname, headers, binOpts] = parseBinOpts(this, options, ['--daemon'], ['--input-file']);
|
|
1287
|
+
[pathname, headers, binOpts] = parseBinOpts(this, options, ['--daemon'], ['--input-file'], options.shellExpansion);
|
|
1284
1288
|
}
|
|
1285
1289
|
try {
|
|
1286
1290
|
if (typeof uri === 'string' && module_1.isURL(uri)) {
|
|
@@ -1530,6 +1534,7 @@ class Request extends module_1 {
|
|
|
1530
1534
|
if (!RCLONE.BIN) {
|
|
1531
1535
|
return Promise.reject((0, types_1.errorMessage)("rclone", "Binary not found"));
|
|
1532
1536
|
}
|
|
1537
|
+
uri = uri.toString();
|
|
1533
1538
|
let pathname, headers, binOpts, silent;
|
|
1534
1539
|
if ((0, types_1.isString)(options)) {
|
|
1535
1540
|
pathname = options;
|
|
@@ -1537,17 +1542,15 @@ class Request extends module_1 {
|
|
|
1537
1542
|
}
|
|
1538
1543
|
else {
|
|
1539
1544
|
silent = options.silent;
|
|
1540
|
-
[pathname, headers, binOpts] = parseBinOpts(this, options, ['--interactive', '--dry-run'], ['--partial-suffix', '--verbose']);
|
|
1545
|
+
[pathname, headers, binOpts] = parseBinOpts(this, options, ['--interactive', '--dry-run'], ['--partial-suffix', '--verbose'], options.shellExpansion);
|
|
1541
1546
|
}
|
|
1542
1547
|
const command = options.command || 'copy';
|
|
1543
1548
|
let source;
|
|
1544
1549
|
switch (command) {
|
|
1545
1550
|
case 'copy':
|
|
1546
1551
|
case 'copyto':
|
|
1547
|
-
source = uri.replace(/^rclone:\?/i, '');
|
|
1548
|
-
break;
|
|
1549
1552
|
case 'copyurl':
|
|
1550
|
-
source = uri;
|
|
1553
|
+
source = uri.replace(REGEXP_RCLONE, '');
|
|
1551
1554
|
break;
|
|
1552
1555
|
default:
|
|
1553
1556
|
return Promise.reject((0, types_1.errorMessage)("rclone", "Invalid command", command || uri));
|
|
@@ -1798,7 +1801,7 @@ class Request extends module_1 {
|
|
|
1798
1801
|
format = format.split('/').pop().split('-').pop();
|
|
1799
1802
|
}
|
|
1800
1803
|
headers ||= {};
|
|
1801
|
-
switch (format = format.
|
|
1804
|
+
switch (format = format.toLowerCase()) {
|
|
1802
1805
|
case 'yaml':
|
|
1803
1806
|
headers.accept = 'application/yaml, application/x-yaml, text/yaml, text/x-yaml';
|
|
1804
1807
|
break;
|
|
@@ -2091,6 +2094,7 @@ class Request extends module_1 {
|
|
|
2091
2094
|
request.emit('error', err);
|
|
2092
2095
|
})
|
|
2093
2096
|
.once('end', () => {
|
|
2097
|
+
request.emit('trailers', response.trailers);
|
|
2094
2098
|
request.emit('end');
|
|
2095
2099
|
});
|
|
2096
2100
|
if (expectContinue) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.4",
|
|
4
4
|
"description": "Request constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"license": "BSD-3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/module": "0.12.
|
|
24
|
-
"@e-mc/types": "0.12.
|
|
23
|
+
"@e-mc/module": "0.12.4",
|
|
24
|
+
"@e-mc/types": "0.12.4",
|
|
25
25
|
"combined-stream": "^1.0.8",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
|
-
"picomatch": "^4.0.
|
|
27
|
+
"picomatch": "^4.0.3",
|
|
28
28
|
"which": "^4.0.0"
|
|
29
29
|
}
|
|
30
30
|
}
|