@e-mc/request 0.9.7 → 0.10.0
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 +6 -4
- package/http/host/index.d.ts +4 -4
- package/http/host/index.js +38 -9
- package/index.d.ts +4 -4
- package/index.js +831 -664
- package/package.json +3 -3
- package/util.js +16 -17
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.0/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IModule, ModuleConstructor } from "./index";
|
|
@@ -131,6 +131,7 @@ interface RequestModule {
|
|
|
131
131
|
h2c?: string[];
|
|
132
132
|
h2?: string[];
|
|
133
133
|
};
|
|
134
|
+
write_stream?: Record<string, number | string>;
|
|
134
135
|
post_limit?: number | string;
|
|
135
136
|
settings?: {
|
|
136
137
|
broadcast_id?: string | string[];
|
|
@@ -150,6 +151,7 @@ interface DownloadModule {
|
|
|
150
151
|
update_status?: number | { interval?: number; broadcast_only?: boolean };
|
|
151
152
|
max_concurrent_downloads?: number;
|
|
152
153
|
max_connection_per_server?: number;
|
|
154
|
+
check_integrity?: boolean;
|
|
153
155
|
bt_stop_timeout?: number;
|
|
154
156
|
bt_tracker_connect_timeout?: number;
|
|
155
157
|
bt_tracker_timeout?: number;
|
|
@@ -201,9 +203,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
|
|
|
201
203
|
|
|
202
204
|
## References
|
|
203
205
|
|
|
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.
|
|
206
|
+
- https://www.unpkg.com/@e-mc/types@0.10.0/lib/http.d.ts
|
|
207
|
+
- https://www.unpkg.com/@e-mc/types@0.10.0/lib/request.d.ts
|
|
208
|
+
- https://www.unpkg.com/@e-mc/types@0.10.0/lib/settings.d.ts
|
|
207
209
|
|
|
208
210
|
* https://www.npmjs.com/package/@types/node
|
|
209
211
|
|
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
|
@@ -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;
|
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;
|