@e-mc/request 0.10.1 → 0.10.3
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/LICENSE +10 -10
- package/README.md +215 -214
- package/http/host/index.d.ts +4 -4
- package/http/host/index.js +2 -2
- package/index.d.ts +4 -4
- package/index.js +123 -100
- package/package.json +30 -30
- package/util.d.ts +28 -27
- package/util.js +39 -13
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.10.
|
|
4
|
-
"description": "Request constructor for E-mc.",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"types": "index.d.ts",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/anpham6/e-mc.git",
|
|
13
|
-
"directory": "src/request"
|
|
14
|
-
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"squared",
|
|
17
|
-
"squared-functions"
|
|
18
|
-
],
|
|
19
|
-
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "BSD
|
|
21
|
-
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@e-mc/module": "0.10.
|
|
24
|
-
"@e-mc/types": "0.10.
|
|
25
|
-
"combined-stream": "^1.0.8",
|
|
26
|
-
"js-yaml": "^4.1.0",
|
|
27
|
-
"picomatch": "^4.0.2",
|
|
28
|
-
"which": "^2.0.2"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@e-mc/request",
|
|
3
|
+
"version": "0.10.3",
|
|
4
|
+
"description": "Request constructor for E-mc.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/e-mc.git",
|
|
13
|
+
"directory": "src/request"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"squared",
|
|
17
|
+
"squared-functions"
|
|
18
|
+
],
|
|
19
|
+
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
+
"license": "BSD-3-Clause",
|
|
21
|
+
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@e-mc/module": "0.10.3",
|
|
24
|
+
"@e-mc/types": "0.10.3",
|
|
25
|
+
"combined-stream": "^1.0.8",
|
|
26
|
+
"js-yaml": "^4.1.0",
|
|
27
|
+
"picomatch": "^4.0.2",
|
|
28
|
+
"which": "^2.0.2"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/util.d.ts
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import type { AuthValue } from '
|
|
2
|
-
import type { HttpProxySettings } from '
|
|
3
|
-
|
|
4
|
-
import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
|
|
5
|
-
import type { Readable, Writable } from 'stream';
|
|
6
|
-
|
|
7
|
-
declare namespace util {
|
|
8
|
-
function parseHeader<T = unknown>(headers: IncomingHttpHeaders, name: string): T | undefined;
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
function getBasicAuth(
|
|
12
|
-
function
|
|
13
|
-
function
|
|
14
|
-
function
|
|
15
|
-
function
|
|
16
|
-
function
|
|
17
|
-
function
|
|
18
|
-
function
|
|
19
|
-
function
|
|
20
|
-
function
|
|
21
|
-
function
|
|
22
|
-
function
|
|
23
|
-
function
|
|
24
|
-
function
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import type { AuthValue } from '@e-mc/types/lib/http';
|
|
2
|
+
import type { HttpProxySettings } from '@e-mc/types/lib/settings';
|
|
3
|
+
|
|
4
|
+
import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
|
|
5
|
+
import type { Readable, Writable } from 'stream';
|
|
6
|
+
|
|
7
|
+
declare namespace util {
|
|
8
|
+
function parseHeader<T = unknown>(headers: IncomingHttpHeaders, name: string): T | undefined;
|
|
9
|
+
function parseOutgoingHeaders(headers: OutgoingHttpHeaders | Headers | undefined): OutgoingHttpHeaders | undefined;
|
|
10
|
+
function normalizeHeaders(headers: OutgoingHttpHeaders): OutgoingHttpHeaders;
|
|
11
|
+
function getBasicAuth(auth: AuthValue): string;
|
|
12
|
+
function getBasicAuth(username: unknown, password?: unknown): string;
|
|
13
|
+
function hasBasicAuth(value: string): boolean;
|
|
14
|
+
function checkRetryable(err: unknown): boolean;
|
|
15
|
+
function isRetryable(value: number, timeout?: boolean): boolean;
|
|
16
|
+
function parseHttpProxy(value?: string, ignoreEnv?: boolean): HttpProxySettings | undefined;
|
|
17
|
+
function trimPath(value: string): string;
|
|
18
|
+
function asInt(value: unknown): number;
|
|
19
|
+
function asFloat(value: unknown): number;
|
|
20
|
+
function fromSeconds(value: unknown): number;
|
|
21
|
+
function getTransferRate(length: number, timeMs: number, unitSeparator?: string): string;
|
|
22
|
+
function hasSameStat(src: string, dest: string, keepEmpty?: boolean): boolean;
|
|
23
|
+
function hasSize(value: string, keepEmpty?: boolean): boolean;
|
|
24
|
+
function getSize(value: string, diskUsed?: boolean): number;
|
|
25
|
+
function byteLength(value: Bufferable, encoding?: BufferEncoding): number;
|
|
26
|
+
function cleanupStream(target: Readable | Writable, pathname?: string): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
28
29
|
export = util;
|
package/util.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
exports.parseHeader = parseHeader;
|
|
3
|
+
exports.parseOutgoingHeaders = parseOutgoingHeaders;
|
|
3
4
|
exports.normalizeHeaders = normalizeHeaders;
|
|
4
5
|
exports.getBasicAuth = getBasicAuth;
|
|
5
6
|
exports.hasBasicAuth = hasBasicAuth;
|
|
@@ -19,8 +20,8 @@ exports.cleanupStream = cleanupStream;
|
|
|
19
20
|
const path = require("path");
|
|
20
21
|
const fs = require("fs");
|
|
21
22
|
const util = require("util");
|
|
22
|
-
const module_1 = require("@e-mc/module");
|
|
23
23
|
const types_1 = require("@e-mc/types");
|
|
24
|
+
const module_1 = require("@e-mc/module");
|
|
24
25
|
const SUPPORTED_USVSTRING = (0, types_1.supported)(16, 8);
|
|
25
26
|
const safeInt = (value) => value >= 0 ? Math.min(value, Number.MAX_SAFE_INTEGER) : NaN;
|
|
26
27
|
function parseHeader(headers, name) {
|
|
@@ -40,6 +41,23 @@ function parseHeader(headers, name) {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
}
|
|
44
|
+
function parseOutgoingHeaders(headers) {
|
|
45
|
+
if (headers) {
|
|
46
|
+
if (globalThis.Headers && headers instanceof Headers) {
|
|
47
|
+
const result = {};
|
|
48
|
+
headers.forEach((value, key) => {
|
|
49
|
+
if (key === 'set-cookie') {
|
|
50
|
+
(result[key] ||= []).push(value);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
result[key] = value;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
return headers;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
43
61
|
function normalizeHeaders(headers) {
|
|
44
62
|
const result = Object.create(null);
|
|
45
63
|
for (const name in headers) {
|
|
@@ -52,11 +70,11 @@ function normalizeHeaders(headers) {
|
|
|
52
70
|
value = value.trim();
|
|
53
71
|
break;
|
|
54
72
|
default:
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
break;
|
|
73
|
+
if (!(0, types_1.isArray)(value)) {
|
|
74
|
+
continue;
|
|
58
75
|
}
|
|
59
|
-
|
|
76
|
+
value = value.map(out => module_1.asString(out).trim());
|
|
77
|
+
break;
|
|
60
78
|
}
|
|
61
79
|
if (value) {
|
|
62
80
|
result[trimPath(name.trim().toLowerCase())] = value;
|
|
@@ -113,28 +131,36 @@ function isRetryable(value, timeout) {
|
|
|
113
131
|
case 502:
|
|
114
132
|
case 503:
|
|
115
133
|
case 521:
|
|
116
|
-
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
134
|
+
return !timeout;
|
|
119
135
|
default:
|
|
120
136
|
return false;
|
|
121
137
|
}
|
|
122
138
|
}
|
|
123
|
-
function parseHttpProxy(value) {
|
|
124
|
-
|
|
139
|
+
function parseHttpProxy(value, ignoreEnv) {
|
|
140
|
+
if (!ignoreEnv) {
|
|
141
|
+
value ||= process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
|
|
142
|
+
}
|
|
125
143
|
if (value) {
|
|
126
144
|
try {
|
|
127
145
|
const url = new URL(value);
|
|
128
146
|
if (url.port) {
|
|
129
147
|
let exclude;
|
|
130
|
-
if (process.env.NO_PROXY) {
|
|
148
|
+
if (process.env.NO_PROXY && !ignoreEnv) {
|
|
131
149
|
exclude = [];
|
|
132
|
-
for (
|
|
150
|
+
for (let item of process.env.NO_PROXY.trim().split(/\s*,\s*/)) {
|
|
151
|
+
if (item === '*') {
|
|
152
|
+
exclude = ['**'];
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
133
155
|
if (module_1.isURL(item)) {
|
|
134
156
|
exclude.push(item);
|
|
135
157
|
}
|
|
136
158
|
else {
|
|
137
|
-
|
|
159
|
+
const negate = item.startsWith('!') ? (item = item.substring(1), '!') : '';
|
|
160
|
+
if (!/^(?:[^.]+|(?:\d+\.){3}\d+)$/.test(item) && !item.includes('*')) {
|
|
161
|
+
item = '*' + item;
|
|
162
|
+
}
|
|
163
|
+
exclude.push(`${negate}http?(s)://${item}?(/)**`);
|
|
138
164
|
}
|
|
139
165
|
}
|
|
140
166
|
}
|