@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/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
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.10.1/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IModule, ModuleConstructor } from "./index";
|
|
@@ -117,6 +117,7 @@ interface RequestModule {
|
|
|
117
117
|
proxy?: {
|
|
118
118
|
address?: string;
|
|
119
119
|
port?: number;
|
|
120
|
+
origin?: string;
|
|
120
121
|
username?: string;
|
|
121
122
|
password?: string;
|
|
122
123
|
include?: string[];
|
|
@@ -131,6 +132,7 @@ interface RequestModule {
|
|
|
131
132
|
h2c?: string[];
|
|
132
133
|
h2?: string[];
|
|
133
134
|
};
|
|
135
|
+
write_stream?: Record<string, number | string>;
|
|
134
136
|
post_limit?: number | string;
|
|
135
137
|
settings?: {
|
|
136
138
|
broadcast_id?: string | string[];
|
|
@@ -150,6 +152,7 @@ interface DownloadModule {
|
|
|
150
152
|
update_status?: number | { interval?: number; broadcast_only?: boolean };
|
|
151
153
|
max_concurrent_downloads?: number;
|
|
152
154
|
max_connection_per_server?: number;
|
|
155
|
+
check_integrity?: boolean;
|
|
153
156
|
bt_stop_timeout?: number;
|
|
154
157
|
bt_tracker_connect_timeout?: number;
|
|
155
158
|
bt_tracker_timeout?: number;
|
|
@@ -201,9 +204,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
|
|
|
201
204
|
|
|
202
205
|
## References
|
|
203
206
|
|
|
204
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
205
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
206
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
207
|
+
- https://www.unpkg.com/@e-mc/types@0.10.1/lib/http.d.ts
|
|
208
|
+
- https://www.unpkg.com/@e-mc/types@0.10.1/lib/request.d.ts
|
|
209
|
+
- https://www.unpkg.com/@e-mc/types@0.10.1/lib/settings.d.ts
|
|
207
210
|
|
|
208
211
|
* https://www.npmjs.com/package/@types/node
|
|
209
212
|
|
package/http/host/index.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a, _b, _c, _d;
|
|
3
3
|
const tls = require("tls");
|
|
4
|
+
const types_1 = require("@e-mc/types");
|
|
4
5
|
const kProtocol = Symbol('protocol');
|
|
5
6
|
const kSecure = Symbol('secure');
|
|
6
7
|
const kHostname = Symbol('hostname');
|
|
7
8
|
const kPort = Symbol('port');
|
|
8
9
|
const kOrigin = Symbol('origin');
|
|
10
|
+
const kStreamSize = Symbol('streamSize');
|
|
9
11
|
const kVersion = Symbol('version');
|
|
10
12
|
const kVersionData = Symbol('versionData');
|
|
11
13
|
const kAltSvc = Symbol('altSvc');
|
|
12
14
|
const kAltSvcQueue = Symbol('altSvcQueue');
|
|
13
15
|
const kAltSvcError = Symbol('altSvcError');
|
|
14
16
|
const HOST_LOCAL = new Set(['localhost']);
|
|
17
|
+
const HOST_STREAM = new Map();
|
|
15
18
|
const HOST_HTTP_1_1 = [];
|
|
16
19
|
const HOST_ALPN_H2C = [];
|
|
17
20
|
const HOST_ALPN_H2 = [];
|
|
@@ -36,13 +39,15 @@ class HttpHost {
|
|
|
36
39
|
return { authorization: 'Basic ' + Buffer.from(auth, 'base64') };
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
|
-
static defineLocalHost(
|
|
42
|
+
static defineLocalHost(values) {
|
|
40
43
|
HOST_LOCAL.clear();
|
|
41
|
-
|
|
44
|
+
for (const address of values) {
|
|
45
|
+
HOST_LOCAL.add(address);
|
|
46
|
+
}
|
|
42
47
|
}
|
|
43
|
-
static defineProtocolNegotiation(
|
|
44
|
-
const { h2c, h2 } =
|
|
45
|
-
const http11 =
|
|
48
|
+
static defineProtocolNegotiation(data) {
|
|
49
|
+
const { h2c, h2 } = data;
|
|
50
|
+
const http11 = data['http/1.1'];
|
|
46
51
|
if (Array.isArray(http11)) {
|
|
47
52
|
HOST_HTTP_1_1.push(...http11.map(address => this.normalizeOrigin(address)));
|
|
48
53
|
}
|
|
@@ -53,6 +58,21 @@ class HttpHost {
|
|
|
53
58
|
HOST_ALPN_H2.push(...h2.map(address => this.normalizeOrigin(address)));
|
|
54
59
|
}
|
|
55
60
|
}
|
|
61
|
+
static defineHostConfig({ write_stream, localhost, protocol }) {
|
|
62
|
+
for (const host in write_stream) {
|
|
63
|
+
const size = (0, types_1.alignSize)(+write_stream[host], 1, 1);
|
|
64
|
+
if (size > 0) {
|
|
65
|
+
const [hostname, port = '443'] = host.split(/\s*:\s*/).map((item, index) => index === 1 ? parseInt(item) > 0 ? parseInt(item).toString() : '443' : item);
|
|
66
|
+
HOST_STREAM.set(hostname + ':' + port, size);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if ((0, types_1.isArray)(localhost)) {
|
|
70
|
+
this.defineLocalHost(localhost);
|
|
71
|
+
}
|
|
72
|
+
if (protocol) {
|
|
73
|
+
this.defineProtocolNegotiation(protocol);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
56
76
|
constructor(url, httpVersion = 1) {
|
|
57
77
|
this[_a] = [
|
|
58
78
|
[0, 0, 0, 1, -1],
|
|
@@ -72,6 +92,7 @@ class HttpHost {
|
|
|
72
92
|
this[kPort] = port;
|
|
73
93
|
this[kOrigin] = url.origin;
|
|
74
94
|
this.localhost = HOST_LOCAL.has(hostname);
|
|
95
|
+
this[kStreamSize] = HOST_STREAM.get(address) || (this.localhost ? 65536 : 4096);
|
|
75
96
|
if (protocol !== 'file:' && !HOST_HTTP_1_1.includes(address = protocol + '//' + address)) {
|
|
76
97
|
if (secure) {
|
|
77
98
|
this[kVersion] = HOST_ALPN_H2.includes(address) ? 2 : httpVersion;
|
|
@@ -83,7 +104,9 @@ class HttpHost {
|
|
|
83
104
|
}
|
|
84
105
|
}
|
|
85
106
|
this[kVersion] = 1;
|
|
86
|
-
|
|
107
|
+
for (const version of this[kVersionData]) {
|
|
108
|
+
version[4] = 0;
|
|
109
|
+
}
|
|
87
110
|
}
|
|
88
111
|
async hasProtocol(version) {
|
|
89
112
|
if (version > 1) {
|
|
@@ -194,7 +217,7 @@ class HttpHost {
|
|
|
194
217
|
]);
|
|
195
218
|
}
|
|
196
219
|
}
|
|
197
|
-
if (addresses.length) {
|
|
220
|
+
if (addresses.length > 0) {
|
|
198
221
|
this.closeAltSvc();
|
|
199
222
|
this[kAltSvcQueue] = addresses.sort((a, b) => {
|
|
200
223
|
if (a[0] === hostname) {
|
|
@@ -275,7 +298,11 @@ class HttpHost {
|
|
|
275
298
|
this.closeAltSvc();
|
|
276
299
|
this[kAltSvcQueue] = [];
|
|
277
300
|
this[kAltSvcError] = [];
|
|
278
|
-
|
|
301
|
+
for (const item of this[kVersionData]) {
|
|
302
|
+
if (item[3]) {
|
|
303
|
+
item[4] = -1;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
279
306
|
}
|
|
280
307
|
}
|
|
281
308
|
flagAltSvc(version, value) {
|
|
@@ -321,7 +348,9 @@ class HttpHost {
|
|
|
321
348
|
get origin() {
|
|
322
349
|
return this[kAltSvc][4] || this[kOrigin];
|
|
323
350
|
}
|
|
351
|
+
get streamSize() {
|
|
352
|
+
return this[kStreamSize];
|
|
353
|
+
}
|
|
324
354
|
}
|
|
325
355
|
_a = kVersionData, _b = kAltSvc, _c = kAltSvcQueue, _d = kAltSvcError;
|
|
326
|
-
|
|
327
356
|
module.exports = HttpHost;
|