@e-mc/request 0.10.0 → 0.10.2
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 +214 -213
- package/http/host/index.d.ts +4 -4
- package/http/host/index.js +2 -2
- package/index.d.ts +4 -4
- package/index.js +39 -48
- package/package.json +30 -30
- package/util.d.ts +27 -25
- package/util.js +47 -4
package/LICENSE
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
3
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
-
|
|
5
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
-
|
|
7
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
|
|
9
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
+
|
|
11
11
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,214 +1,215 @@
|
|
|
1
|
-
# @e-mc/request
|
|
2
|
-
|
|
3
|
-
* NodeJS 16
|
|
4
|
-
* ES2020
|
|
5
|
-
|
|
6
|
-
## General Usage
|
|
7
|
-
|
|
8
|
-
* [Read the Docs](https://e-mc.readthedocs.io)
|
|
9
|
-
|
|
10
|
-
## Interface
|
|
11
|
-
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.10.
|
|
13
|
-
|
|
14
|
-
```typescript
|
|
15
|
-
import type { IModule, ModuleConstructor } from "./index";
|
|
16
|
-
import type { HttpAgentSettings, HttpProtocolVersion, HttpRequestClient, InternetProtocolVersion } from "./http";
|
|
17
|
-
import type { ApplyOptions, Aria2Options, FormDataPart, HeadersOnCallback, HostConfig, OpenOptions, PostOptions, ProxySettings, ReadExpectType, RequestInit, StatusOnCallback } from "./request";
|
|
18
|
-
import type { DnsLookupSettings, RequestModule, RequestSettings } from "./settings";
|
|
19
|
-
|
|
20
|
-
import type { ClientRequest, OutgoingHttpHeaders } from "http";
|
|
21
|
-
import type { LookupFunction } from "net";
|
|
22
|
-
import type { Writable } from "stream";
|
|
23
|
-
|
|
24
|
-
interface IRequest extends IModule {
|
|
25
|
-
module: RequestModule;
|
|
26
|
-
startTime: number;
|
|
27
|
-
acceptEncoding: boolean;
|
|
28
|
-
keepAlive: boolean | null;
|
|
29
|
-
readTimeout: number;
|
|
30
|
-
readExpect: ReadExpectType;
|
|
31
|
-
proxy: ProxySettings | null;
|
|
32
|
-
init(config?: RequestInit): this;
|
|
33
|
-
apply(options: ApplyOptions): this;
|
|
34
|
-
addDns(hostname: string, address: string, timeout: number): void;
|
|
35
|
-
addDns(hostname: string, address: string, family?: string, timeout?: number): void;
|
|
36
|
-
lookupDns(hostname: string): LookupFunction;
|
|
37
|
-
proxyOf(uri: string, localhost?: boolean): ProxySettings | undefined;
|
|
38
|
-
statusOn(name: number | number[], callback: StatusOnCallback): void;
|
|
39
|
-
statusOn(name: number | number[], globUrl: string, callback: StatusOnCallback): void;
|
|
40
|
-
headersOn(name: string | string[], callback: HeadersOnCallback): void;
|
|
41
|
-
headersOn(name: string | string[], globUrl: string, callback: HeadersOnCallback): void;
|
|
42
|
-
headersOf(uri: string): OutgoingHttpHeaders | undefined;
|
|
43
|
-
aria2c(uri: string | URL, pathname: string): Promise<string[]>;
|
|
44
|
-
aria2c(uri: string | URL, options?: Aria2Options): Promise<string[]>;
|
|
45
|
-
json(uri: string | URL, options?: OpenOptions): Promise<object | null>;
|
|
46
|
-
pipe(uri: string | URL, to: Writable, options?: OpenOptions): Promise<null>;
|
|
47
|
-
opts(url: string | URL, options?: OpenOptions): HostConfig;
|
|
48
|
-
open(uri: string | URL, options: OpenOptions): HttpRequestClient;
|
|
49
|
-
head(uri: string | URL, options?: OpenOptions): ClientRequest;
|
|
50
|
-
post(uri: string | URL, data: unknown, contentType: string): Promise<Buffer | string | null>;
|
|
51
|
-
post(uri: string | URL, parts: FormDataPart[]): Promise<Buffer | string | null>;
|
|
52
|
-
post(uri: string | URL, form: Record<string, unknown>, parts: FormDataPart[]): Promise<Buffer | string | null>;
|
|
53
|
-
post(uri: string | URL, data: unknown, options: PostOptions): Promise<Buffer | string | null>;
|
|
54
|
-
post(uri: string | URL, data: unknown, contentType?: string, options?: PostOptions): Promise<Buffer | string | null>;
|
|
55
|
-
get(uri: string | URL, options?: OpenOptions): Promise<Buffer | object | string | null>;
|
|
56
|
-
detach(singleton?: boolean): void;
|
|
57
|
-
reset(): void;
|
|
58
|
-
close(): void;
|
|
59
|
-
set agentTimeout(value);
|
|
60
|
-
get agentTimeout(): number;
|
|
61
|
-
set httpVersion(value);
|
|
62
|
-
get httpVersion(): HttpProtocolVersion | null;
|
|
63
|
-
set ipVersion(value);
|
|
64
|
-
get ipVersion(): InternetProtocolVersion;
|
|
65
|
-
get settings(): RequestSettings;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
interface RequestConstructor extends ModuleConstructor {
|
|
69
|
-
readCACert(value: string, cache?: boolean): string;
|
|
70
|
-
readTLSKey(value: string, cache?: boolean): string;
|
|
71
|
-
readTLSCert(value: string, cache?: boolean): string;
|
|
72
|
-
isCert(value: string): boolean;
|
|
73
|
-
fromURL(url: URL, value: string): string;
|
|
74
|
-
fromStatusCode(value: number | string): string;
|
|
75
|
-
defineHttpAgent(options: HttpAgentSettings): void;
|
|
76
|
-
defineDnsLookup(options: DnsLookupSettings, clear?: boolean): void;
|
|
77
|
-
getAria2Path(): string;
|
|
78
|
-
readonly prototype: IRequest;
|
|
79
|
-
new(module?: RequestModule): IRequest;
|
|
80
|
-
}
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## Settings
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
import type { PermittedDirectories } from "./core";
|
|
87
|
-
import type { SecureConfig } from "./http";
|
|
88
|
-
import type { PurgeComponent } from "./settings";
|
|
89
|
-
|
|
90
|
-
import type { LookupAddress } from "dns";
|
|
91
|
-
import type { OutgoingHttpHeaders } from "http";
|
|
92
|
-
|
|
93
|
-
interface RequestModule {
|
|
94
|
-
handler: "@e-mc/request";
|
|
95
|
-
timeout?: number | string;
|
|
96
|
-
read_timeout?: number | string;
|
|
97
|
-
agent?: {
|
|
98
|
-
keep_alive?: boolean;
|
|
99
|
-
timeout?: number | string;
|
|
100
|
-
};
|
|
101
|
-
connect?: {
|
|
102
|
-
timeout?: number | string;
|
|
103
|
-
retry_wait?: number | string;
|
|
104
|
-
retry_after?: number | string;
|
|
105
|
-
retry_limit?: number;
|
|
106
|
-
redirect_limit?: number;
|
|
107
|
-
};
|
|
108
|
-
dns?: {
|
|
109
|
-
family?: number;
|
|
110
|
-
expires?: number | string;
|
|
111
|
-
resolve?: Record<string, Partial<LookupAddress>>;
|
|
112
|
-
};
|
|
113
|
-
use?: {
|
|
114
|
-
http_version?: 1 | 2;
|
|
115
|
-
accept_encoding?: boolean;
|
|
116
|
-
};
|
|
117
|
-
proxy?: {
|
|
118
|
-
address?: string;
|
|
119
|
-
port?: number;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
- https://www.unpkg.com/@e-mc/types@0.10.
|
|
208
|
-
- https://www.unpkg.com/@e-mc/types@0.10.
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
1
|
+
# @e-mc/request
|
|
2
|
+
|
|
3
|
+
* NodeJS 16
|
|
4
|
+
* ES2020
|
|
5
|
+
|
|
6
|
+
## General Usage
|
|
7
|
+
|
|
8
|
+
* [Read the Docs](https://e-mc.readthedocs.io)
|
|
9
|
+
|
|
10
|
+
## Interface
|
|
11
|
+
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.10.2/lib/index.d.ts)
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import type { IModule, ModuleConstructor } from "./index";
|
|
16
|
+
import type { HttpAgentSettings, HttpProtocolVersion, HttpRequestClient, InternetProtocolVersion } from "./http";
|
|
17
|
+
import type { ApplyOptions, Aria2Options, FormDataPart, HeadersOnCallback, HostConfig, OpenOptions, PostOptions, ProxySettings, ReadExpectType, RequestInit, StatusOnCallback } from "./request";
|
|
18
|
+
import type { DnsLookupSettings, RequestModule, RequestSettings } from "./settings";
|
|
19
|
+
|
|
20
|
+
import type { ClientRequest, OutgoingHttpHeaders } from "http";
|
|
21
|
+
import type { LookupFunction } from "net";
|
|
22
|
+
import type { Writable } from "stream";
|
|
23
|
+
|
|
24
|
+
interface IRequest extends IModule {
|
|
25
|
+
module: RequestModule;
|
|
26
|
+
startTime: number;
|
|
27
|
+
acceptEncoding: boolean;
|
|
28
|
+
keepAlive: boolean | null;
|
|
29
|
+
readTimeout: number;
|
|
30
|
+
readExpect: ReadExpectType;
|
|
31
|
+
proxy: ProxySettings | null;
|
|
32
|
+
init(config?: RequestInit): this;
|
|
33
|
+
apply(options: ApplyOptions): this;
|
|
34
|
+
addDns(hostname: string, address: string, timeout: number): void;
|
|
35
|
+
addDns(hostname: string, address: string, family?: string, timeout?: number): void;
|
|
36
|
+
lookupDns(hostname: string): LookupFunction;
|
|
37
|
+
proxyOf(uri: string, localhost?: boolean): ProxySettings | undefined;
|
|
38
|
+
statusOn(name: number | number[], callback: StatusOnCallback): void;
|
|
39
|
+
statusOn(name: number | number[], globUrl: string, callback: StatusOnCallback): void;
|
|
40
|
+
headersOn(name: string | string[], callback: HeadersOnCallback): void;
|
|
41
|
+
headersOn(name: string | string[], globUrl: string, callback: HeadersOnCallback): void;
|
|
42
|
+
headersOf(uri: string): OutgoingHttpHeaders | undefined;
|
|
43
|
+
aria2c(uri: string | URL, pathname: string): Promise<string[]>;
|
|
44
|
+
aria2c(uri: string | URL, options?: Aria2Options): Promise<string[]>;
|
|
45
|
+
json(uri: string | URL, options?: OpenOptions): Promise<object | null>;
|
|
46
|
+
pipe(uri: string | URL, to: Writable, options?: OpenOptions): Promise<null>;
|
|
47
|
+
opts(url: string | URL, options?: OpenOptions): HostConfig;
|
|
48
|
+
open(uri: string | URL, options: OpenOptions): HttpRequestClient;
|
|
49
|
+
head(uri: string | URL, options?: OpenOptions): ClientRequest;
|
|
50
|
+
post(uri: string | URL, data: unknown, contentType: string): Promise<Buffer | string | null>;
|
|
51
|
+
post(uri: string | URL, parts: FormDataPart[]): Promise<Buffer | string | null>;
|
|
52
|
+
post(uri: string | URL, form: Record<string, unknown>, parts: FormDataPart[]): Promise<Buffer | string | null>;
|
|
53
|
+
post(uri: string | URL, data: unknown, options: PostOptions): Promise<Buffer | string | null>;
|
|
54
|
+
post(uri: string | URL, data: unknown, contentType?: string, options?: PostOptions): Promise<Buffer | string | null>;
|
|
55
|
+
get(uri: string | URL, options?: OpenOptions): Promise<Buffer | object | string | null>;
|
|
56
|
+
detach(singleton?: boolean): void;
|
|
57
|
+
reset(): void;
|
|
58
|
+
close(): void;
|
|
59
|
+
set agentTimeout(value);
|
|
60
|
+
get agentTimeout(): number;
|
|
61
|
+
set httpVersion(value);
|
|
62
|
+
get httpVersion(): HttpProtocolVersion | null;
|
|
63
|
+
set ipVersion(value);
|
|
64
|
+
get ipVersion(): InternetProtocolVersion;
|
|
65
|
+
get settings(): RequestSettings;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface RequestConstructor extends ModuleConstructor {
|
|
69
|
+
readCACert(value: string, cache?: boolean): string;
|
|
70
|
+
readTLSKey(value: string, cache?: boolean): string;
|
|
71
|
+
readTLSCert(value: string, cache?: boolean): string;
|
|
72
|
+
isCert(value: string): boolean;
|
|
73
|
+
fromURL(url: URL, value: string): string;
|
|
74
|
+
fromStatusCode(value: number | string): string;
|
|
75
|
+
defineHttpAgent(options: HttpAgentSettings): void;
|
|
76
|
+
defineDnsLookup(options: DnsLookupSettings, clear?: boolean): void;
|
|
77
|
+
getAria2Path(): string;
|
|
78
|
+
readonly prototype: IRequest;
|
|
79
|
+
new(module?: RequestModule): IRequest;
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Settings
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import type { PermittedDirectories } from "./core";
|
|
87
|
+
import type { SecureConfig } from "./http";
|
|
88
|
+
import type { PurgeComponent } from "./settings";
|
|
89
|
+
|
|
90
|
+
import type { LookupAddress } from "dns";
|
|
91
|
+
import type { OutgoingHttpHeaders } from "http";
|
|
92
|
+
|
|
93
|
+
interface RequestModule {
|
|
94
|
+
handler: "@e-mc/request";
|
|
95
|
+
timeout?: number | string;
|
|
96
|
+
read_timeout?: number | string;
|
|
97
|
+
agent?: {
|
|
98
|
+
keep_alive?: boolean;
|
|
99
|
+
timeout?: number | string;
|
|
100
|
+
};
|
|
101
|
+
connect?: {
|
|
102
|
+
timeout?: number | string;
|
|
103
|
+
retry_wait?: number | string;
|
|
104
|
+
retry_after?: number | string;
|
|
105
|
+
retry_limit?: number;
|
|
106
|
+
redirect_limit?: number;
|
|
107
|
+
};
|
|
108
|
+
dns?: {
|
|
109
|
+
family?: number;
|
|
110
|
+
expires?: number | string;
|
|
111
|
+
resolve?: Record<string, Partial<LookupAddress>>;
|
|
112
|
+
};
|
|
113
|
+
use?: {
|
|
114
|
+
http_version?: 1 | 2;
|
|
115
|
+
accept_encoding?: boolean;
|
|
116
|
+
};
|
|
117
|
+
proxy?: {
|
|
118
|
+
address?: string;
|
|
119
|
+
port?: number;
|
|
120
|
+
origin?: string;
|
|
121
|
+
username?: string;
|
|
122
|
+
password?: string;
|
|
123
|
+
include?: string[];
|
|
124
|
+
exclude?: string[];
|
|
125
|
+
keep_alive?: boolean;
|
|
126
|
+
};
|
|
127
|
+
headers: Record<string, OutgoingHttpHeaders>;
|
|
128
|
+
certs?: Record<string, SecureConfig<string | string[]>>;
|
|
129
|
+
localhost?: string[];
|
|
130
|
+
protocol?: {
|
|
131
|
+
"http/1.1"?: string[];
|
|
132
|
+
h2c?: string[];
|
|
133
|
+
h2?: string[];
|
|
134
|
+
};
|
|
135
|
+
write_stream?: Record<string, number | string>;
|
|
136
|
+
post_limit?: number | string;
|
|
137
|
+
settings?: {
|
|
138
|
+
broadcast_id?: string | string[];
|
|
139
|
+
time_format?: "readable" | "relative" | "none";
|
|
140
|
+
purge?: PurgeComponent;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
interface DownloadModule {
|
|
145
|
+
expires?: number | string;
|
|
146
|
+
aria2?: {
|
|
147
|
+
bin?: string | false;
|
|
148
|
+
exec?: {
|
|
149
|
+
uid?: number;
|
|
150
|
+
gid?: number;
|
|
151
|
+
};
|
|
152
|
+
update_status?: number | { interval?: number; broadcast_only?: boolean };
|
|
153
|
+
max_concurrent_downloads?: number;
|
|
154
|
+
max_connection_per_server?: number;
|
|
155
|
+
check_integrity?: boolean;
|
|
156
|
+
bt_stop_timeout?: number;
|
|
157
|
+
bt_tracker_connect_timeout?: number;
|
|
158
|
+
bt_tracker_timeout?: number;
|
|
159
|
+
min_split_size?: string;
|
|
160
|
+
disk_cache?: number | string;
|
|
161
|
+
lowest_speed_limit?: number | string;
|
|
162
|
+
always_resume?: boolean;
|
|
163
|
+
file_allocation?: "none" | "prealloc" | "trunc" | "falloc";
|
|
164
|
+
conf_path?: string;
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Example usage
|
|
170
|
+
|
|
171
|
+
```javascript
|
|
172
|
+
const Request = require("@e-mc/request");
|
|
173
|
+
|
|
174
|
+
const instance = new Request({
|
|
175
|
+
read_timeout: 30,
|
|
176
|
+
connect: {
|
|
177
|
+
timeout: 20, // Seconds
|
|
178
|
+
retry_wait: 1,
|
|
179
|
+
retry_after: 30,
|
|
180
|
+
retry_limit: 3, // Max attempts
|
|
181
|
+
redirect_limit: 10
|
|
182
|
+
},
|
|
183
|
+
use: {
|
|
184
|
+
http_version: 2,
|
|
185
|
+
accept_encoding: true
|
|
186
|
+
},
|
|
187
|
+
dns: {
|
|
188
|
+
family: 4 // ipVersion
|
|
189
|
+
},
|
|
190
|
+
agent: { keep_alive: true }
|
|
191
|
+
});
|
|
192
|
+
request.init({ ipVersion: 6 });
|
|
193
|
+
|
|
194
|
+
const options = {
|
|
195
|
+
format: "yaml",
|
|
196
|
+
httpVersion: 1,
|
|
197
|
+
silent: true,
|
|
198
|
+
headers: { "x-goog-user-project": "project-1" }
|
|
199
|
+
};
|
|
200
|
+
instance.get("http://hostname/path/config.yml", options).then(data => {
|
|
201
|
+
console.log(data.property);
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## References
|
|
206
|
+
|
|
207
|
+
- https://www.unpkg.com/@e-mc/types@0.10.2/lib/http.d.ts
|
|
208
|
+
- https://www.unpkg.com/@e-mc/types@0.10.2/lib/request.d.ts
|
|
209
|
+
- https://www.unpkg.com/@e-mc/types@0.10.2/lib/settings.d.ts
|
|
210
|
+
|
|
211
|
+
* https://www.npmjs.com/package/@types/node
|
|
212
|
+
|
|
213
|
+
## LICENSE
|
|
214
|
+
|
|
214
215
|
BSD 3-Clause
|
package/http/host/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { HttpHostConstructor } from '../../../types/lib/request';
|
|
2
|
-
|
|
3
|
-
declare const HttpHost: HttpHostConstructor;
|
|
4
|
-
|
|
1
|
+
import type { HttpHostConstructor } from '../../../types/lib/request';
|
|
2
|
+
|
|
3
|
+
declare const HttpHost: HttpHostConstructor;
|
|
4
|
+
|
|
5
5
|
export = HttpHost;
|
package/http/host/index.js
CHANGED
|
@@ -120,7 +120,7 @@ class HttpHost {
|
|
|
120
120
|
case 1:
|
|
121
121
|
return status;
|
|
122
122
|
default:
|
|
123
|
-
return this._tlsConnect
|
|
123
|
+
return this._tlsConnect ||= new Promise(resolve => {
|
|
124
124
|
const alpn = 'h' + version;
|
|
125
125
|
const socket = tls.connect(+this.port, this.hostname, { ALPNProtocols: [alpn], requestCert: true, rejectUnauthorized: false }, () => {
|
|
126
126
|
this._tlsConnect = null;
|
|
@@ -147,7 +147,7 @@ class HttpHost {
|
|
|
147
147
|
resolve(data[3] = 0);
|
|
148
148
|
})
|
|
149
149
|
.end();
|
|
150
|
-
})
|
|
150
|
+
});
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
return 1;
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RequestConstructor } from '../types/lib';
|
|
2
|
-
|
|
3
|
-
declare const Request: RequestConstructor;
|
|
4
|
-
|
|
1
|
+
import type { RequestConstructor } from '../types/lib';
|
|
2
|
+
|
|
3
|
+
declare const Request: RequestConstructor;
|
|
4
|
+
|
|
5
5
|
export = Request;
|
package/index.js
CHANGED
|
@@ -11,7 +11,7 @@ const dns = require("dns");
|
|
|
11
11
|
const net = require("net");
|
|
12
12
|
const stream = require("stream");
|
|
13
13
|
const zlib = require("zlib");
|
|
14
|
-
const qs = require("querystring");
|
|
14
|
+
const qs = require("node:querystring");
|
|
15
15
|
const combined = require("combined-stream");
|
|
16
16
|
const pm = require("picomatch");
|
|
17
17
|
const yaml = require("js-yaml");
|
|
@@ -96,7 +96,7 @@ function getBaseHeaders(uri, headers) {
|
|
|
96
96
|
let result;
|
|
97
97
|
for (const pathname in headers) {
|
|
98
98
|
if (pathname === uri || uri.startsWith(pathname + '/')) {
|
|
99
|
-
(result
|
|
99
|
+
(result ||= []).push([pathname, headers[pathname]]);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
if (result) {
|
|
@@ -107,7 +107,7 @@ function getBaseHeaders(uri, headers) {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
function setDnsCache(hostname, value, expires) {
|
|
110
|
-
expires
|
|
110
|
+
expires ??= DNS.EXPIRES;
|
|
111
111
|
if (expires > 0 && !DNS.CACHE[hostname]) {
|
|
112
112
|
DNS.CACHE[hostname] = value;
|
|
113
113
|
if (expires !== Infinity) {
|
|
@@ -129,18 +129,17 @@ function setOutgoingHeaders(output, headers) {
|
|
|
129
129
|
}
|
|
130
130
|
function getProxySettings(request, agentTimeout) {
|
|
131
131
|
const proxy = request.proxy;
|
|
132
|
-
if (proxy
|
|
133
|
-
const
|
|
134
|
-
const address = (!module_1.isURL(proxy.address) ? port === 80 ? 'http://' : 'https://' : '') + proxy.address;
|
|
132
|
+
if (proxy && (proxy.origin || proxy.address && proxy.port)) {
|
|
133
|
+
const origin = proxy.origin || ((!module_1.isURL(proxy.address) ? (0, util_1.asInt)(proxy.port) === 80 ? 'http://' : 'https://' : '') + proxy.address + ':' + proxy.port);
|
|
135
134
|
try {
|
|
136
|
-
let host = new URL(
|
|
135
|
+
let host = new URL(origin), include, exclude;
|
|
137
136
|
if (proxy.username) {
|
|
138
137
|
host = new URL(host.protocol + '//' + (0, util_1.getBasicAuth)(proxy.username, proxy.password) + host.host);
|
|
139
138
|
}
|
|
140
139
|
if ((0, types_1.isArray)(proxy.include)) {
|
|
141
140
|
include = proxy.include;
|
|
142
141
|
}
|
|
143
|
-
|
|
142
|
+
if ((0, types_1.isArray)(proxy.exclude)) {
|
|
144
143
|
exclude = proxy.exclude;
|
|
145
144
|
}
|
|
146
145
|
return { host, include, exclude, keepAlive: proxy.keep_alive, agentTimeout };
|
|
@@ -760,7 +759,7 @@ class Fetch {
|
|
|
760
759
|
redirectResponse(statusCode, location) {
|
|
761
760
|
this.abortResponse();
|
|
762
761
|
if (location) {
|
|
763
|
-
if (this.config.follow_redirect === false) {
|
|
762
|
+
if (this.config.follow_redirect === false || this.config.followRedirect === false) {
|
|
764
763
|
this.rejectError(this.formatStatus(statusCode, "Follow redirect was disabled"));
|
|
765
764
|
}
|
|
766
765
|
else if (++this.redirects <= this.redirectLimit) {
|
|
@@ -1343,7 +1342,6 @@ class Request extends module_1 {
|
|
|
1343
1342
|
const output = [];
|
|
1344
1343
|
let count = 0;
|
|
1345
1344
|
this[kConnectHttp].forEach((protocol, index) => {
|
|
1346
|
-
var _p;
|
|
1347
1345
|
const title = 'HTTP' + (index + 1);
|
|
1348
1346
|
for (const origin in protocol) {
|
|
1349
1347
|
const value = protocol[origin];
|
|
@@ -1353,7 +1351,7 @@ class Request extends module_1 {
|
|
|
1353
1351
|
if (item[1] === title && Array.isArray(item[2]) && item[2][0].startsWith(origin)) {
|
|
1354
1352
|
item[1] = '';
|
|
1355
1353
|
item[2][0] = item[2][0].substring(origin.length);
|
|
1356
|
-
|
|
1354
|
+
item[4].titleBgColor &&= undefined;
|
|
1357
1355
|
item[4].titleJustify = 'right';
|
|
1358
1356
|
args.push(item);
|
|
1359
1357
|
log.splice(i--, 1);
|
|
@@ -1415,7 +1413,7 @@ class Request extends module_1 {
|
|
|
1415
1413
|
if (config) {
|
|
1416
1414
|
const { headers, httpVersion, ipVersion, readTimeout } = config;
|
|
1417
1415
|
if ((0, types_1.isObject)(headers)) {
|
|
1418
|
-
setOutgoingHeaders(this[kHeaders]
|
|
1416
|
+
setOutgoingHeaders(this[kHeaders] ||= {}, headers);
|
|
1419
1417
|
}
|
|
1420
1418
|
if (httpVersion !== undefined) {
|
|
1421
1419
|
this.httpVersion = httpVersion;
|
|
@@ -1505,7 +1503,6 @@ class Request extends module_1 {
|
|
|
1505
1503
|
setDnsCache(hostname, this[kConnectDns][hostname] = [{ address, family }], timeout);
|
|
1506
1504
|
}
|
|
1507
1505
|
lookupDns(hostname) {
|
|
1508
|
-
var _p;
|
|
1509
1506
|
const resolved = this[kConnectDns][hostname] || DNS.CACHE[hostname];
|
|
1510
1507
|
if (resolved) {
|
|
1511
1508
|
return (...args) => {
|
|
@@ -1517,7 +1514,7 @@ class Request extends module_1 {
|
|
|
1517
1514
|
}
|
|
1518
1515
|
};
|
|
1519
1516
|
}
|
|
1520
|
-
const pending =
|
|
1517
|
+
const pending = this[kPendingDns][hostname] ||= [];
|
|
1521
1518
|
return (value, options, callback) => {
|
|
1522
1519
|
if (pending.push(callback) === 1) {
|
|
1523
1520
|
let ipVersion = this.ipVersion;
|
|
@@ -1566,7 +1563,7 @@ class Request extends module_1 {
|
|
|
1566
1563
|
return proxy;
|
|
1567
1564
|
}
|
|
1568
1565
|
if ((0, types_1.isArray)(include) && !include.some(value => REGEXP_GLOBWITHIN.test(value) ? pm.isMatch(uri, value) : uri.startsWith(value)) || (0, types_1.isArray)(exclude) && exclude.some(value => REGEXP_GLOBWITHIN.test(value) ? pm.isMatch(uri, value) : uri.startsWith(value))) {
|
|
1569
|
-
return
|
|
1566
|
+
return;
|
|
1570
1567
|
}
|
|
1571
1568
|
return proxy;
|
|
1572
1569
|
}
|
|
@@ -1577,7 +1574,7 @@ class Request extends module_1 {
|
|
|
1577
1574
|
globUrl = '*';
|
|
1578
1575
|
}
|
|
1579
1576
|
if ((0, types_1.isString)(globUrl) && typeof callback === 'function') {
|
|
1580
|
-
const on = this[kStatusOn]
|
|
1577
|
+
const on = this[kStatusOn] ||= new Map();
|
|
1581
1578
|
for (const item of !Array.isArray(code) ? [code] : code) {
|
|
1582
1579
|
let status = on.get(item);
|
|
1583
1580
|
if (!status) {
|
|
@@ -1593,7 +1590,7 @@ class Request extends module_1 {
|
|
|
1593
1590
|
globUrl = '*';
|
|
1594
1591
|
}
|
|
1595
1592
|
if ((0, types_1.isString)(globUrl) && typeof callback === 'function') {
|
|
1596
|
-
const on = this[kHeadersOn]
|
|
1593
|
+
const on = this[kHeadersOn] ||= new Map();
|
|
1597
1594
|
for (const item of !Array.isArray(name) ? [name] : name) {
|
|
1598
1595
|
let headers = on.get(item);
|
|
1599
1596
|
if (!headers) {
|
|
@@ -1682,7 +1679,7 @@ class Request extends module_1 {
|
|
|
1682
1679
|
if (!module_1.createDir(pathname)) {
|
|
1683
1680
|
return Promise.reject((0, types_1.errorMessage)("aria2", "Path is not a directory", pathname));
|
|
1684
1681
|
}
|
|
1685
|
-
silent
|
|
1682
|
+
silent ??= this[kSingleton];
|
|
1686
1683
|
return new Promise((resolve, reject) => {
|
|
1687
1684
|
let protocol, origin, username, password;
|
|
1688
1685
|
if (uri instanceof URL) {
|
|
@@ -1887,7 +1884,7 @@ class Request extends module_1 {
|
|
|
1887
1884
|
if (match[3] === '100') {
|
|
1888
1885
|
result.push(file);
|
|
1889
1886
|
}
|
|
1890
|
-
messageUnit
|
|
1887
|
+
messageUnit ||= match[2];
|
|
1891
1888
|
break;
|
|
1892
1889
|
case 'INPR':
|
|
1893
1890
|
if (ARIA2.ALWAYS_RESUME) {
|
|
@@ -1963,7 +1960,6 @@ class Request extends module_1 {
|
|
|
1963
1960
|
return this.get(uri, options);
|
|
1964
1961
|
}
|
|
1965
1962
|
opts(url, options) {
|
|
1966
|
-
var _p, _q, _r, _s;
|
|
1967
1963
|
const base = this[kBaseURL];
|
|
1968
1964
|
if (base) {
|
|
1969
1965
|
if (typeof url === 'string') {
|
|
@@ -1978,15 +1974,14 @@ class Request extends module_1 {
|
|
|
1978
1974
|
}
|
|
1979
1975
|
let host;
|
|
1980
1976
|
if (this.host) {
|
|
1981
|
-
host =
|
|
1977
|
+
host = HTTP.HOST[url.origin] ||= new host_1(url, HTTP.VERSION);
|
|
1982
1978
|
}
|
|
1983
1979
|
else {
|
|
1984
|
-
host =
|
|
1980
|
+
host = this[kHostInfo][url.origin] ||= new host_1(url, this.httpVersion || 1);
|
|
1985
1981
|
}
|
|
1986
1982
|
return { ...options, host, url };
|
|
1987
1983
|
}
|
|
1988
1984
|
open(uri, options) {
|
|
1989
|
-
var _p, _q;
|
|
1990
1985
|
let { host, url, httpVersion, method = 'GET', search, encoding, format, headers, postData, keepAlive, agentTimeout, socketPath, timeout = this._config.connectTimeout, outStream } = options;
|
|
1991
1986
|
const getting = method === 'GET';
|
|
1992
1987
|
const posting = method === 'POST';
|
|
@@ -1998,7 +1993,7 @@ class Request extends module_1 {
|
|
|
1998
1993
|
if (format.includes('/')) {
|
|
1999
1994
|
format = format.split('/').pop().split('-').pop();
|
|
2000
1995
|
}
|
|
2001
|
-
headers
|
|
1996
|
+
headers ||= {};
|
|
2002
1997
|
switch (format = format.trim().toLowerCase()) {
|
|
2003
1998
|
case 'yaml':
|
|
2004
1999
|
headers.accept = 'application/yaml, application/x-yaml, text/yaml, text/x-yaml';
|
|
@@ -2047,7 +2042,7 @@ class Request extends module_1 {
|
|
|
2047
2042
|
this[kBaseURL] = [url, httpVersion, headers];
|
|
2048
2043
|
}
|
|
2049
2044
|
else if (base) {
|
|
2050
|
-
httpVersion
|
|
2045
|
+
httpVersion ??= base[1];
|
|
2051
2046
|
if (base[2]) {
|
|
2052
2047
|
headers = { ...base[2], ...headers };
|
|
2053
2048
|
}
|
|
@@ -2064,7 +2059,7 @@ class Request extends module_1 {
|
|
|
2064
2059
|
const version = this.httpVersion;
|
|
2065
2060
|
let request, ca, cert, key, ciphers, minVersion, baseHeaders = this.headersOf(uri);
|
|
2066
2061
|
if (getting && this.acceptEncoding && !localhost && !baseHeaders?.['accept-encoding']) {
|
|
2067
|
-
(
|
|
2062
|
+
(headers ||= {})['accept-encoding'] ||= 'gzip, deflate, br' + (LIB_ZSTD ? ', zstd' : '');
|
|
2068
2063
|
}
|
|
2069
2064
|
if (secure) {
|
|
2070
2065
|
const certs = this[kCerts]?.[0][origin] || this.host && TLS.TEXT[origin];
|
|
@@ -2073,7 +2068,7 @@ class Request extends module_1 {
|
|
|
2073
2068
|
}
|
|
2074
2069
|
}
|
|
2075
2070
|
if (!proxy && httpVersion !== 1 && ((httpVersion || host.version) === 2 && version !== 1 || secure && version === 2 && host.failed(2, true) === 0)) {
|
|
2076
|
-
request = (
|
|
2071
|
+
request = (this[kSession][0][origin] ||= http2.connect(origin, { lookup: this.lookupDns(hostname), ca, cert, key, ciphers, minVersion, settings: localhost ? { maxFrameSize: 16777215, enablePush: false } : { enablePush: false } })).request({ ...baseHeaders, ...host_1.getBasicAuth(url), ...headers, ':path': pathname, ':method': method });
|
|
2077
2072
|
if (getting) {
|
|
2078
2073
|
const listenerMap = {};
|
|
2079
2074
|
const onEvent = request.on.bind(request);
|
|
@@ -2114,7 +2109,6 @@ class Request extends module_1 {
|
|
|
2114
2109
|
this.matchHeaders(url, response, request, options);
|
|
2115
2110
|
});
|
|
2116
2111
|
request.on = function (event, listener) {
|
|
2117
|
-
var _p;
|
|
2118
2112
|
switch (event) {
|
|
2119
2113
|
case 'data':
|
|
2120
2114
|
case 'error':
|
|
@@ -2124,7 +2118,7 @@ class Request extends module_1 {
|
|
|
2124
2118
|
break;
|
|
2125
2119
|
}
|
|
2126
2120
|
if (!connected) {
|
|
2127
|
-
(listenerMap[
|
|
2121
|
+
(listenerMap[event + '-on'] ||= []).push(listener);
|
|
2128
2122
|
}
|
|
2129
2123
|
default:
|
|
2130
2124
|
onEvent(event, listener);
|
|
@@ -2133,7 +2127,6 @@ class Request extends module_1 {
|
|
|
2133
2127
|
return this;
|
|
2134
2128
|
};
|
|
2135
2129
|
request.once = function (event, listener) {
|
|
2136
|
-
var _p;
|
|
2137
2130
|
switch (event) {
|
|
2138
2131
|
case 'data':
|
|
2139
2132
|
case 'error':
|
|
@@ -2143,7 +2136,7 @@ class Request extends module_1 {
|
|
|
2143
2136
|
break;
|
|
2144
2137
|
}
|
|
2145
2138
|
if (!connected) {
|
|
2146
|
-
(listenerMap[
|
|
2139
|
+
(listenerMap[event + '-once'] ||= []).push(listener);
|
|
2147
2140
|
}
|
|
2148
2141
|
default:
|
|
2149
2142
|
onceEvent(event, listener);
|
|
@@ -2160,11 +2153,10 @@ class Request extends module_1 {
|
|
|
2160
2153
|
if (proxy) {
|
|
2161
2154
|
const pkg = secure ? 'https-proxy-agent' : 'http-proxy-agent';
|
|
2162
2155
|
try {
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
agent = require(pkg)(keepAlive
|
|
2167
|
-
const proxyHeaders = this[kHeaders] && getBaseHeaders(href, this[kHeaders]) || getBaseHeaders(href, HTTP.HEADERS);
|
|
2156
|
+
keepAlive ??= proxy.keepAlive;
|
|
2157
|
+
agentTimeout ??= proxy.agentTimeout;
|
|
2158
|
+
const proxyHeaders = this[kHeaders] && getBaseHeaders(proxy.host.href, this[kHeaders]) || getBaseHeaders(proxy.host.href, HTTP.HEADERS);
|
|
2159
|
+
agent = require(pkg)(proxy.host, typeof keepAlive === 'boolean' || agentTimeout > 0 || proxyHeaders ? { keepAlive: keepAlive ?? true, timeout: agentTimeout, headers: proxyHeaders } : undefined);
|
|
2168
2160
|
if (proxyHeaders) {
|
|
2169
2161
|
baseHeaders = { ...baseHeaders, ...proxyHeaders };
|
|
2170
2162
|
}
|
|
@@ -2180,7 +2172,7 @@ class Request extends module_1 {
|
|
|
2180
2172
|
agent = new (secure ? https.Agent : http.Agent)({ keepAlive: true, timeout: agentTimeout });
|
|
2181
2173
|
}
|
|
2182
2174
|
else if (agentTimeout !== 0) {
|
|
2183
|
-
agentTimeout
|
|
2175
|
+
agentTimeout ??= this.agentTimeout;
|
|
2184
2176
|
if (this.keepAlive !== null || agentTimeout > 0) {
|
|
2185
2177
|
agent = new (secure ? https.Agent : http.Agent)({ keepAlive: this.keepAlive ?? true, timeout: agentTimeout });
|
|
2186
2178
|
}
|
|
@@ -2329,16 +2321,16 @@ class Request extends module_1 {
|
|
|
2329
2321
|
let formData;
|
|
2330
2322
|
({ formData, dataEncoding } = options);
|
|
2331
2323
|
if (formData) {
|
|
2332
|
-
(parts
|
|
2324
|
+
(parts ||= []).push(...Array.isArray(formData) ? formData : [formData]);
|
|
2333
2325
|
}
|
|
2334
2326
|
else {
|
|
2335
|
-
contentType
|
|
2327
|
+
contentType ||= options.contentType;
|
|
2336
2328
|
}
|
|
2337
2329
|
}
|
|
2338
2330
|
else {
|
|
2339
2331
|
options = {};
|
|
2340
2332
|
}
|
|
2341
|
-
const headers = options.headers
|
|
2333
|
+
const headers = options.headers ||= {};
|
|
2342
2334
|
for (const attr in headers) {
|
|
2343
2335
|
const name = attr.toLowerCase();
|
|
2344
2336
|
if (name === 'content-type' || name === 'content-length') {
|
|
@@ -2377,8 +2369,8 @@ class Request extends module_1 {
|
|
|
2377
2369
|
}
|
|
2378
2370
|
if (target) {
|
|
2379
2371
|
if (typeof target === 'string') {
|
|
2380
|
-
filename
|
|
2381
|
-
type
|
|
2372
|
+
filename ||= path.basename(target);
|
|
2373
|
+
type ||= module_1.lookupMime(filename);
|
|
2382
2374
|
target = fs.readFileSync(target);
|
|
2383
2375
|
}
|
|
2384
2376
|
else if (target instanceof stream.Readable) {
|
|
@@ -2395,7 +2387,7 @@ class Request extends module_1 {
|
|
|
2395
2387
|
const result = await module_1.resolveMime(target);
|
|
2396
2388
|
let ext;
|
|
2397
2389
|
if (result) {
|
|
2398
|
-
type
|
|
2390
|
+
type ||= result.mime;
|
|
2399
2391
|
ext = result.ext;
|
|
2400
2392
|
}
|
|
2401
2393
|
else if (type) {
|
|
@@ -2438,7 +2430,7 @@ class Request extends module_1 {
|
|
|
2438
2430
|
}
|
|
2439
2431
|
else {
|
|
2440
2432
|
data = JSON.stringify(data);
|
|
2441
|
-
contentType
|
|
2433
|
+
contentType ||= "application/json";
|
|
2442
2434
|
}
|
|
2443
2435
|
headers['content-length'] = Buffer.byteLength(data, (0, types_1.getEncoding)(dataEncoding)).toString();
|
|
2444
2436
|
}
|
|
@@ -2528,11 +2520,11 @@ class Request extends module_1 {
|
|
|
2528
2520
|
set agentTimeout(value) {
|
|
2529
2521
|
if (value > 0) {
|
|
2530
2522
|
this[kAgentTimeout] = value;
|
|
2531
|
-
this.keepAlive
|
|
2523
|
+
this.keepAlive ??= true;
|
|
2532
2524
|
}
|
|
2533
2525
|
else {
|
|
2534
2526
|
this[kAgentTimeout] = 0;
|
|
2535
|
-
this.keepAlive
|
|
2527
|
+
this.keepAlive ??= false;
|
|
2536
2528
|
}
|
|
2537
2529
|
}
|
|
2538
2530
|
get agentTimeout() {
|
|
@@ -2562,8 +2554,7 @@ class Request extends module_1 {
|
|
|
2562
2554
|
return this[kIpVersion];
|
|
2563
2555
|
}
|
|
2564
2556
|
get settings() {
|
|
2565
|
-
|
|
2566
|
-
return (_p = this.module).settings || (_p.settings = {});
|
|
2557
|
+
return this.module.settings ||= {};
|
|
2567
2558
|
}
|
|
2568
2559
|
}
|
|
2569
2560
|
_a = kSingleton, _b = kHttpVersion, _c = kHeaders, _d = kCerts, _e = kBaseURL, _f = kConnectDns, _g = kPendingDns, _h = kConnectHttp, _j = kStatusOn, _k = kHeadersOn, _l = kDownloading, _m = kHostInfo, _o = kSession;
|
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 3-Clause",
|
|
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.2",
|
|
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.2",
|
|
24
|
+
"@e-mc/types": "0.10.2",
|
|
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,26 +1,28 @@
|
|
|
1
|
-
import type { AuthValue } from '../types/lib/http';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function
|
|
9
|
-
function
|
|
10
|
-
function getBasicAuth(
|
|
11
|
-
function
|
|
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
|
-
|
|
25
|
-
|
|
1
|
+
import type { AuthValue } from '../types/lib/http';
|
|
2
|
+
import type { HttpProxySettings } from '../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 normalizeHeaders(headers: OutgoingHttpHeaders): OutgoingHttpHeaders;
|
|
10
|
+
function getBasicAuth(auth: AuthValue): string;
|
|
11
|
+
function getBasicAuth(username: unknown, password?: unknown): string;
|
|
12
|
+
function hasBasicAuth(value: string): boolean;
|
|
13
|
+
function checkRetryable(err: unknown): boolean;
|
|
14
|
+
function isRetryable(value: number, timeout?: boolean): boolean;
|
|
15
|
+
function parseHttpProxy(value?: string, ignoreEnv?: boolean): HttpProxySettings | undefined;
|
|
16
|
+
function trimPath(value: string): string;
|
|
17
|
+
function asInt(value: unknown): number;
|
|
18
|
+
function asFloat(value: unknown): number;
|
|
19
|
+
function fromSeconds(value: unknown): number;
|
|
20
|
+
function getTransferRate(length: number, timeMs: number, unitSeparator?: string): string;
|
|
21
|
+
function hasSameStat(src: string, dest: string, keepEmpty?: boolean): boolean;
|
|
22
|
+
function hasSize(value: string, keepEmpty?: boolean): boolean;
|
|
23
|
+
function getSize(value: string, diskUsed?: boolean): number;
|
|
24
|
+
function byteLength(value: Bufferable, encoding?: BufferEncoding): number;
|
|
25
|
+
function cleanupStream(target: Readable | Writable, pathname?: string): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
26
28
|
export = util;
|
package/util.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.getBasicAuth = getBasicAuth;
|
|
|
5
5
|
exports.hasBasicAuth = hasBasicAuth;
|
|
6
6
|
exports.checkRetryable = checkRetryable;
|
|
7
7
|
exports.isRetryable = isRetryable;
|
|
8
|
+
exports.parseHttpProxy = parseHttpProxy;
|
|
8
9
|
exports.trimPath = trimPath;
|
|
9
10
|
exports.asInt = asInt;
|
|
10
11
|
exports.asFloat = asFloat;
|
|
@@ -17,8 +18,10 @@ exports.byteLength = byteLength;
|
|
|
17
18
|
exports.cleanupStream = cleanupStream;
|
|
18
19
|
const path = require("path");
|
|
19
20
|
const fs = require("fs");
|
|
21
|
+
const util = require("util");
|
|
20
22
|
const module_1 = require("@e-mc/module");
|
|
21
23
|
const types_1 = require("@e-mc/types");
|
|
24
|
+
const SUPPORTED_USVSTRING = (0, types_1.supported)(16, 8);
|
|
22
25
|
const safeInt = (value) => value >= 0 ? Math.min(value, Number.MAX_SAFE_INTEGER) : NaN;
|
|
23
26
|
function parseHeader(headers, name) {
|
|
24
27
|
const value = headers[name];
|
|
@@ -65,7 +68,7 @@ function getBasicAuth(username, password) {
|
|
|
65
68
|
if ((0, types_1.isObject)(username)) {
|
|
66
69
|
({ username, password } = username);
|
|
67
70
|
}
|
|
68
|
-
return (0, types_1.isString)(username) ? encodeURIComponent(username) + ((0, types_1.isString)(password) ? ':' + encodeURIComponent(password) : '') + '@' : '';
|
|
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) : '') + '@' : '';
|
|
69
72
|
}
|
|
70
73
|
function hasBasicAuth(value) {
|
|
71
74
|
try {
|
|
@@ -110,13 +113,53 @@ function isRetryable(value, timeout) {
|
|
|
110
113
|
case 502:
|
|
111
114
|
case 503:
|
|
112
115
|
case 521:
|
|
113
|
-
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
+
return !timeout;
|
|
116
117
|
default:
|
|
117
118
|
return false;
|
|
118
119
|
}
|
|
119
120
|
}
|
|
121
|
+
function parseHttpProxy(value, ignoreEnv) {
|
|
122
|
+
if (!ignoreEnv) {
|
|
123
|
+
value ||= process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
|
|
124
|
+
}
|
|
125
|
+
if (value) {
|
|
126
|
+
try {
|
|
127
|
+
const url = new URL(value);
|
|
128
|
+
if (url.port) {
|
|
129
|
+
let exclude;
|
|
130
|
+
if (process.env.NO_PROXY && !ignoreEnv) {
|
|
131
|
+
exclude = [];
|
|
132
|
+
for (let item of process.env.NO_PROXY.trim().split(/\s*,\s*/)) {
|
|
133
|
+
if (item === '*') {
|
|
134
|
+
exclude = ['**'];
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
if (module_1.isURL(item)) {
|
|
138
|
+
exclude.push(item);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
const negate = item.startsWith('!') ? (item = item.substring(1), '!') : '';
|
|
142
|
+
if (!/^(?:[^.]+|(?:\d+\.){3}\d+)$/.test(item) && !item.includes('*')) {
|
|
143
|
+
item = '*' + item;
|
|
144
|
+
}
|
|
145
|
+
exclude.push(`${negate}http?(s)://${item}?(/)**`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
address: url.protocol + '//' + url.hostname,
|
|
151
|
+
port: url.port,
|
|
152
|
+
origin: url.origin,
|
|
153
|
+
username: url.username ? decodeURIComponent(url.username) : '',
|
|
154
|
+
password: url.password ? decodeURIComponent(url.password) : '',
|
|
155
|
+
exclude
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
120
163
|
function trimPath(value) {
|
|
121
164
|
const length = value.length - 1;
|
|
122
165
|
return value[length] === '/' ? value.substring(0, length) : value;
|