bdy 1.9.31-dev → 1.9.33-beta
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/distTs/package.json
CHANGED
|
@@ -36,7 +36,10 @@ class ServerHttp2 extends events_1.default {
|
|
|
36
36
|
const address = this.server.address();
|
|
37
37
|
if (!address || !address.port)
|
|
38
38
|
return;
|
|
39
|
-
let client = http2_1.default.connect(`http://localhost:${address.port}
|
|
39
|
+
let client = http2_1.default.connect(`http://localhost:${address.port}`, {
|
|
40
|
+
maxSessionMemory: 100,
|
|
41
|
+
noDelay: true
|
|
42
|
+
});
|
|
40
43
|
let req = client.request(logRequest.headers);
|
|
41
44
|
if (logRequest.requestBody.data.length > 0)
|
|
42
45
|
req.write(logRequest.requestBody.data);
|
package/distTs/src/ssh/client.js
CHANGED
|
@@ -39,7 +39,7 @@ class SshClient extends events_1.default {
|
|
|
39
39
|
hmac: ['hmac-sha2-256-etm@openssh.com'],
|
|
40
40
|
kex: ['ecdh-sha2-nistp256'],
|
|
41
41
|
},
|
|
42
|
-
keepaliveInterval:
|
|
42
|
+
keepaliveInterval: 30000,
|
|
43
43
|
host: this.ip,
|
|
44
44
|
port: this.port,
|
|
45
45
|
username: this.username,
|
|
@@ -69,6 +69,7 @@ class SshClient extends events_1.default {
|
|
|
69
69
|
return Buffer.concat([data, newData]);
|
|
70
70
|
}
|
|
71
71
|
async processStream(stream, info) {
|
|
72
|
+
stream.allowHalfOpen = false;
|
|
72
73
|
if (stream.readableFlowing)
|
|
73
74
|
stream.pause();
|
|
74
75
|
stream.on('error', () => {
|
|
@@ -9,14 +9,14 @@ const http2_1 = __importDefault(require("http2"));
|
|
|
9
9
|
const uuid_1 = require("uuid");
|
|
10
10
|
const texts_js_1 = require("../texts.js");
|
|
11
11
|
const CONNECTION_TIMEOUT = 5000;
|
|
12
|
-
const STREAM_LIMIT =
|
|
12
|
+
const STREAM_LIMIT = 10;
|
|
13
13
|
class TunnelAgent {
|
|
14
14
|
static getHttp1() {
|
|
15
15
|
if (!this.httpAgent1) {
|
|
16
16
|
this.httpAgent1 = new http_1.default.Agent({
|
|
17
17
|
noDelay: true,
|
|
18
18
|
keepAlive: true,
|
|
19
|
-
maxSockets:
|
|
19
|
+
maxSockets: 20,
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
return this.httpAgent1;
|
|
@@ -26,7 +26,7 @@ class TunnelAgent {
|
|
|
26
26
|
this.httpsAgent1 = new https_1.default.Agent({
|
|
27
27
|
noDelay: true,
|
|
28
28
|
keepAlive: true,
|
|
29
|
-
maxSockets:
|
|
29
|
+
maxSockets: 20,
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
return this.httpsAgent1;
|
|
@@ -39,6 +39,7 @@ class TunnelAgent {
|
|
|
39
39
|
}, CONNECTION_TIMEOUT);
|
|
40
40
|
const client = http2_1.default.connect(authority, {
|
|
41
41
|
rejectUnauthorized: verify,
|
|
42
|
+
maxSessionMemory: 100,
|
|
42
43
|
noDelay: true,
|
|
43
44
|
servername,
|
|
44
45
|
});
|
|
@@ -121,25 +121,27 @@ class TunnelHttp extends events_1.default {
|
|
|
121
121
|
}
|
|
122
122
|
return h;
|
|
123
123
|
}
|
|
124
|
-
getClearedHeaders(headers = {}, compressionMethod) {
|
|
124
|
+
getClearedHeaders(headers = {}, compressionMethod, allowUpgrade = false) {
|
|
125
125
|
const hop = [
|
|
126
126
|
':method',
|
|
127
127
|
':path',
|
|
128
128
|
':scheme',
|
|
129
129
|
':authority',
|
|
130
130
|
':status',
|
|
131
|
-
'keep-alive',
|
|
132
131
|
'host',
|
|
133
|
-
'connection',
|
|
134
132
|
'proxy-authenticate',
|
|
135
133
|
'proxy-connection',
|
|
136
|
-
'
|
|
134
|
+
'proxy-authorization',
|
|
137
135
|
'trailer',
|
|
138
|
-
'upgrade',
|
|
139
136
|
'transfer-encoding',
|
|
140
137
|
'strict-transport-security',
|
|
141
138
|
'te',
|
|
142
139
|
];
|
|
140
|
+
if (!(allowUpgrade && headers.connection === 'Upgrade')) {
|
|
141
|
+
hop.push('upgrade');
|
|
142
|
+
hop.push('connection');
|
|
143
|
+
hop.push('keep-alive');
|
|
144
|
+
}
|
|
143
145
|
const tmp = {};
|
|
144
146
|
if (compressionMethod &&
|
|
145
147
|
compressionMethod !== utils_1.TUNNEL_COMPRESSION_METHOD_IDENTITY) {
|
|
@@ -152,6 +154,15 @@ class TunnelHttp extends events_1.default {
|
|
|
152
154
|
tmp[name] = headers[name];
|
|
153
155
|
}
|
|
154
156
|
});
|
|
157
|
+
tmp['access-control-allow-origin'] = '*';
|
|
158
|
+
if (tmp['set-cookie']) {
|
|
159
|
+
const setCookie = [];
|
|
160
|
+
const h = (this.req.headers.host || this.req.headers[':authority'] || '').split(':')[0];
|
|
161
|
+
tmp['set-cookie'].forEach((cookie) => {
|
|
162
|
+
setCookie.push(cookie.replaceAll(/([dD]omain)=[\w_\-\\.]+/ig, `$1=${h}`));
|
|
163
|
+
});
|
|
164
|
+
tmp['set-cookie'] = setCookie;
|
|
165
|
+
}
|
|
155
166
|
return tmp;
|
|
156
167
|
}
|
|
157
168
|
getPath() {
|
|
@@ -169,7 +180,7 @@ class TunnelHttp extends events_1.default {
|
|
|
169
180
|
const method = this.getMethod();
|
|
170
181
|
const path = this.getPath();
|
|
171
182
|
const headers = {
|
|
172
|
-
...this.getClearedHeaders(reqHeaders),
|
|
183
|
+
...this.getClearedHeaders(reqHeaders, null, true),
|
|
173
184
|
...this.headers,
|
|
174
185
|
...this.getRequestHeaders(false),
|
|
175
186
|
};
|
|
@@ -184,6 +195,7 @@ class TunnelHttp extends events_1.default {
|
|
|
184
195
|
headers,
|
|
185
196
|
});
|
|
186
197
|
this.logRequest = this.httpLog.newRequest(method, headers, path, utils_1.TUNNEL_IDENTIFIED_HTTP1, this.req);
|
|
198
|
+
r.on('upgrade', (proxyRes, socket, head) => this.upgrade(proxyRes, socket, head));
|
|
187
199
|
r.on('response', (proxyRes) => {
|
|
188
200
|
this.proxyRes = proxyRes;
|
|
189
201
|
const statusCode = this.proxyRes.statusCode;
|
|
@@ -209,7 +221,7 @@ class TunnelHttp extends events_1.default {
|
|
|
209
221
|
const reqHeaders = this.req.headers;
|
|
210
222
|
const method = this.getMethod();
|
|
211
223
|
const headers = {
|
|
212
|
-
...this.getClearedHeaders(reqHeaders),
|
|
224
|
+
...this.getClearedHeaders(reqHeaders, null, true),
|
|
213
225
|
...this.headers,
|
|
214
226
|
...this.getRequestHeaders(false),
|
|
215
227
|
};
|
|
@@ -226,6 +238,7 @@ class TunnelHttp extends events_1.default {
|
|
|
226
238
|
headers,
|
|
227
239
|
});
|
|
228
240
|
this.logRequest = this.httpLog.newRequest(method, headers, path, utils_1.TUNNEL_IDENTIFIED_HTTP1, this.req);
|
|
241
|
+
r.on('upgrade', (proxyRes, socket, head) => this.upgrade(proxyRes, socket, head));
|
|
229
242
|
r.on('response', (proxyRes) => {
|
|
230
243
|
this.proxyRes = proxyRes;
|
|
231
244
|
const statusCode = this.proxyRes.statusCode;
|
|
@@ -339,6 +352,47 @@ class TunnelHttp extends events_1.default {
|
|
|
339
352
|
this.logRequest = null;
|
|
340
353
|
}
|
|
341
354
|
}
|
|
355
|
+
upgrade(proxyRes, socket, head) {
|
|
356
|
+
const resHeaders = proxyRes.headers;
|
|
357
|
+
const reqSocket = this.req.socket;
|
|
358
|
+
this.httpLog.newResponse(this.req, 101, resHeaders, this.logRequest);
|
|
359
|
+
this.clear();
|
|
360
|
+
socket.setTimeout(0);
|
|
361
|
+
const headers = this.getClearedHeaders(resHeaders, null, true);
|
|
362
|
+
let msg = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n';
|
|
363
|
+
Object.keys(headers).forEach((k) => {
|
|
364
|
+
const v = headers[k];
|
|
365
|
+
if (Array.isArray(v)) {
|
|
366
|
+
v.forEach((vv) => {
|
|
367
|
+
msg += `${k}: ${vv}\r\n`;
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
msg += `${k}: ${v}\r\n`;
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
msg += '\r\n';
|
|
375
|
+
reqSocket.removeAllListeners();
|
|
376
|
+
socket.removeAllListeners();
|
|
377
|
+
reqSocket.on('close', () => {
|
|
378
|
+
reqSocket.removeAllListeners();
|
|
379
|
+
this.emit(utils_1.HTTP1_SOCKET_CLOSED, reqSocket);
|
|
380
|
+
});
|
|
381
|
+
socket.on('close', () => {
|
|
382
|
+
socket.removeAllListeners();
|
|
383
|
+
try {
|
|
384
|
+
reqSocket.destroy();
|
|
385
|
+
}
|
|
386
|
+
catch {
|
|
387
|
+
// do nothing
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
if (head && head.length) {
|
|
391
|
+
socket.unshift(head);
|
|
392
|
+
}
|
|
393
|
+
reqSocket.write(msg);
|
|
394
|
+
reqSocket.pipe(socket).pipe(reqSocket);
|
|
395
|
+
}
|
|
342
396
|
async pipe() {
|
|
343
397
|
if (this.serve) {
|
|
344
398
|
try {
|
package/distTs/src/tunnel.js
CHANGED
|
@@ -426,6 +426,7 @@ class Tunnel extends events_1.default {
|
|
|
426
426
|
httpIdentify: this.identify.type,
|
|
427
427
|
httpLog: this.httpLog,
|
|
428
428
|
});
|
|
429
|
+
http.once(utils_js_1.HTTP1_SOCKET_CLOSED, (socket) => this.httpConnectionClosed(socket));
|
|
429
430
|
http.pipe().then();
|
|
430
431
|
}
|
|
431
432
|
tlsSocket(tlsSocket) {
|