@e-mc/request 0.8.11 → 0.8.13
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 +6 -6
- package/README.md +90 -90
- package/http/host/index.d.ts +4 -4
- package/http/host/index.js +4 -4
- package/index.d.ts +4 -4
- package/index.js +1 -1
- package/package.json +30 -30
- package/util.d.ts +16 -16
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
7
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
# @e-mc/request
|
|
2
|
-
|
|
3
|
-
* NodeJS 14
|
|
4
|
-
* ES2019
|
|
5
|
-
|
|
6
|
-
## General Usage
|
|
7
|
-
|
|
8
|
-
* [Read the Docs](https://e-mc.readthedocs.io)
|
|
9
|
-
|
|
10
|
-
## Interface
|
|
11
|
-
|
|
12
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
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?: number | 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[], patternUrl: string, callback: StatusOnCallback): void;
|
|
40
|
-
headersOn(name: string | string[], callback: HeadersOnCallback): void;
|
|
41
|
-
headersOn(name: string | string[], patternUrl: 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
|
-
## References
|
|
84
|
-
|
|
85
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
86
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
87
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
88
|
-
|
|
89
|
-
## LICENSE
|
|
90
|
-
|
|
1
|
+
# @e-mc/request
|
|
2
|
+
|
|
3
|
+
* NodeJS 14
|
|
4
|
+
* ES2019
|
|
5
|
+
|
|
6
|
+
## General Usage
|
|
7
|
+
|
|
8
|
+
* [Read the Docs](https://e-mc.readthedocs.io)
|
|
9
|
+
|
|
10
|
+
## Interface
|
|
11
|
+
|
|
12
|
+
- https://www.unpkg.com/@e-mc/types@0.8.13/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?: number | 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[], patternUrl: string, callback: StatusOnCallback): void;
|
|
40
|
+
headersOn(name: string | string[], callback: HeadersOnCallback): void;
|
|
41
|
+
headersOn(name: string | string[], patternUrl: 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
|
+
## References
|
|
84
|
+
|
|
85
|
+
- https://www.unpkg.com/@e-mc/types@0.8.13/lib/http.d.ts
|
|
86
|
+
- https://www.unpkg.com/@e-mc/types@0.8.13/lib/request.d.ts
|
|
87
|
+
- https://www.unpkg.com/@e-mc/types@0.8.13/lib/settings.d.ts
|
|
88
|
+
|
|
89
|
+
## LICENSE
|
|
90
|
+
|
|
91
91
|
MIT
|
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
|
@@ -102,28 +102,28 @@ class HttpHost {
|
|
|
102
102
|
return this._tlsConnect || (this._tlsConnect = new Promise(resolve => {
|
|
103
103
|
const alpn = 'h' + version;
|
|
104
104
|
const socket = tls.connect(+this.port, this.hostname, { ALPNProtocols: [alpn], requestCert: true, rejectUnauthorized: false }, () => {
|
|
105
|
-
resolve(data[3] = alpn === socket.alpnProtocol ? 1 : 0);
|
|
106
105
|
this._tlsConnect = null;
|
|
106
|
+
resolve(data[3] = alpn === socket.alpnProtocol ? 1 : 0);
|
|
107
107
|
});
|
|
108
108
|
socket
|
|
109
109
|
.setNoDelay(false)
|
|
110
110
|
.setTimeout(10000)
|
|
111
111
|
.on('timeout', () => {
|
|
112
|
+
socket.destroy();
|
|
112
113
|
if (this._tlsConnect) {
|
|
114
|
+
this._tlsConnect = null;
|
|
113
115
|
if (this.error(version) >= 10) {
|
|
114
116
|
resolve(data[3] = 0);
|
|
115
117
|
}
|
|
116
118
|
else {
|
|
117
119
|
resolve(2);
|
|
118
120
|
}
|
|
119
|
-
this._tlsConnect = null;
|
|
120
121
|
}
|
|
121
|
-
socket.destroy();
|
|
122
122
|
})
|
|
123
123
|
.on('error', () => {
|
|
124
124
|
this.failed(version);
|
|
125
|
-
resolve(data[3] = 0);
|
|
126
125
|
this._tlsConnect = null;
|
|
126
|
+
resolve(data[3] = 0);
|
|
127
127
|
})
|
|
128
128
|
.end();
|
|
129
129
|
}));
|
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
|
@@ -2063,10 +2063,10 @@ class Request extends module_1.default {
|
|
|
2063
2063
|
result = encoding && !pipeline ? '' : null;
|
|
2064
2064
|
titleBgColor = 'bgBlue';
|
|
2065
2065
|
}
|
|
2066
|
-
resolve(result);
|
|
2067
2066
|
if (log) {
|
|
2068
2067
|
this.writeTimeProcess('HTTP' + httpVersion, request.statusMessage || url.toString(), startTime, { type: 1024, queue: !!this.host, titleBgColor, messageUnit, messageUnitMinWidth: 9, delayTime, bypassLog: LOG_STDOUT });
|
|
2069
2068
|
}
|
|
2069
|
+
resolve(result);
|
|
2070
2070
|
});
|
|
2071
2071
|
host.success(httpVersion);
|
|
2072
2072
|
};
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.8.
|
|
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": "MIT",
|
|
21
|
-
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@e-mc/module": "0.8.
|
|
24
|
-
"@e-mc/types": "0.8.
|
|
25
|
-
"combined-stream": "^1.0.8",
|
|
26
|
-
"js-yaml": "^4.1.0",
|
|
27
|
-
"picomatch": "^3.0.1",
|
|
28
|
-
"which": "^2.0.2"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@e-mc/request",
|
|
3
|
+
"version": "0.8.13",
|
|
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": "MIT",
|
|
21
|
+
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@e-mc/module": "0.8.13",
|
|
24
|
+
"@e-mc/types": "0.8.13",
|
|
25
|
+
"combined-stream": "^1.0.8",
|
|
26
|
+
"js-yaml": "^4.1.0",
|
|
27
|
+
"picomatch": "^3.0.1",
|
|
28
|
+
"which": "^2.0.2"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/util.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
|
|
2
|
-
|
|
3
|
-
declare namespace util {
|
|
4
|
-
function parseHeader<T = unknown>(headers: IncomingHttpHeaders, name: string): T | undefined;
|
|
5
|
-
function normalizeHeaders(headers: OutgoingHttpHeaders): OutgoingHttpHeaders;
|
|
6
|
-
function getBasicAuth(auth: AuthValue): string;
|
|
7
|
-
function getBasicAuth(username: unknown, password?: unknown): string;
|
|
8
|
-
function hasBasicAuth(value: string): boolean;
|
|
9
|
-
function checkRetryable(err: unknown): boolean;
|
|
10
|
-
function isRetryable(value: number, timeout?: boolean): boolean;
|
|
11
|
-
function trimPath(value: string): string;
|
|
12
|
-
function asInt(value: unknown): number;
|
|
13
|
-
function asFloat(value: unknown): number;
|
|
14
|
-
function fromSeconds(value: unknown): number;
|
|
15
|
-
}
|
|
16
|
-
|
|
1
|
+
import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
|
|
2
|
+
|
|
3
|
+
declare namespace util {
|
|
4
|
+
function parseHeader<T = unknown>(headers: IncomingHttpHeaders, name: string): T | undefined;
|
|
5
|
+
function normalizeHeaders(headers: OutgoingHttpHeaders): OutgoingHttpHeaders;
|
|
6
|
+
function getBasicAuth(auth: AuthValue): string;
|
|
7
|
+
function getBasicAuth(username: unknown, password?: unknown): string;
|
|
8
|
+
function hasBasicAuth(value: string): boolean;
|
|
9
|
+
function checkRetryable(err: unknown): boolean;
|
|
10
|
+
function isRetryable(value: number, timeout?: boolean): boolean;
|
|
11
|
+
function trimPath(value: string): string;
|
|
12
|
+
function asInt(value: unknown): number;
|
|
13
|
+
function asFloat(value: unknown): number;
|
|
14
|
+
function fromSeconds(value: unknown): number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
17
|
export = util;
|