bdy 1.12.8-dev → 1.12.8-dev-pipeline-run

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.
Files changed (156) hide show
  1. package/distTs/package.json +1 -1
  2. package/package.json +1 -1
  3. package/distTs/bin/cli.js +0 -5
  4. package/distTs/src/agent/agent.js +0 -328
  5. package/distTs/src/agent/linux.js +0 -124
  6. package/distTs/src/agent/manager.js +0 -519
  7. package/distTs/src/agent/osx.js +0 -146
  8. package/distTs/src/agent/socket/client.js +0 -178
  9. package/distTs/src/agent/socket/tunnel.js +0 -237
  10. package/distTs/src/agent/socket.js +0 -242
  11. package/distTs/src/agent/system.js +0 -179
  12. package/distTs/src/agent/wait.js +0 -23
  13. package/distTs/src/agent/windows.js +0 -159
  14. package/distTs/src/agent.js +0 -302
  15. package/distTs/src/api/agent.js +0 -99
  16. package/distTs/src/api/buddy.js +0 -139
  17. package/distTs/src/api/socket.js +0 -159
  18. package/distTs/src/cfg.js +0 -234
  19. package/distTs/src/command/agent/disable.js +0 -27
  20. package/distTs/src/command/agent/enable.js +0 -27
  21. package/distTs/src/command/agent/install.js +0 -117
  22. package/distTs/src/command/agent/restart.js +0 -27
  23. package/distTs/src/command/agent/run.js +0 -19
  24. package/distTs/src/command/agent/start.js +0 -28
  25. package/distTs/src/command/agent/status.js +0 -34
  26. package/distTs/src/command/agent/stop.js +0 -28
  27. package/distTs/src/command/agent/target/disable.js +0 -27
  28. package/distTs/src/command/agent/target/enable.js +0 -27
  29. package/distTs/src/command/agent/target/status.js +0 -32
  30. package/distTs/src/command/agent/target.js +0 -15
  31. package/distTs/src/command/agent/tunnel/http.js +0 -43
  32. package/distTs/src/command/agent/tunnel/list.js +0 -27
  33. package/distTs/src/command/agent/tunnel/remove.js +0 -28
  34. package/distTs/src/command/agent/tunnel/start.js +0 -34
  35. package/distTs/src/command/agent/tunnel/status.js +0 -31
  36. package/distTs/src/command/agent/tunnel/tcp.js +0 -43
  37. package/distTs/src/command/agent/tunnel/tls.js +0 -43
  38. package/distTs/src/command/agent/tunnel.js +0 -23
  39. package/distTs/src/command/agent/uninstall.js +0 -44
  40. package/distTs/src/command/agent/update.js +0 -38
  41. package/distTs/src/command/agent/version.js +0 -21
  42. package/distTs/src/command/agent.js +0 -35
  43. package/distTs/src/command/config/add/http.js +0 -25
  44. package/distTs/src/command/config/add/tcp.js +0 -25
  45. package/distTs/src/command/config/add/tls.js +0 -25
  46. package/distTs/src/command/config/add.js +0 -15
  47. package/distTs/src/command/config/get/region.js +0 -15
  48. package/distTs/src/command/config/get/timeout.js +0 -15
  49. package/distTs/src/command/config/get/token.js +0 -15
  50. package/distTs/src/command/config/get/tunnel.js +0 -19
  51. package/distTs/src/command/config/get/tunnels.js +0 -15
  52. package/distTs/src/command/config/get/whitelist.js +0 -15
  53. package/distTs/src/command/config/get.js +0 -21
  54. package/distTs/src/command/config/remove/tunnel.js +0 -19
  55. package/distTs/src/command/config/remove.js +0 -11
  56. package/distTs/src/command/config/set/region.js +0 -17
  57. package/distTs/src/command/config/set/timeout.js +0 -17
  58. package/distTs/src/command/config/set/token.js +0 -16
  59. package/distTs/src/command/config/set/whitelist.js +0 -17
  60. package/distTs/src/command/config/set.js +0 -17
  61. package/distTs/src/command/config.js +0 -17
  62. package/distTs/src/command/http.js +0 -30
  63. package/distTs/src/command/pre.js +0 -49
  64. package/distTs/src/command/start.js +0 -28
  65. package/distTs/src/command/tcp.js +0 -30
  66. package/distTs/src/command/tls.js +0 -30
  67. package/distTs/src/command/tunnel/config.js +0 -17
  68. package/distTs/src/command/tunnel/http.js +0 -31
  69. package/distTs/src/command/tunnel/start.js +0 -28
  70. package/distTs/src/command/tunnel/tcp.js +0 -30
  71. package/distTs/src/command/tunnel/tls.js +0 -30
  72. package/distTs/src/command/tunnel.js +0 -19
  73. package/distTs/src/command/ut/upload.js +0 -108
  74. package/distTs/src/command/ut.js +0 -12
  75. package/distTs/src/command/version.js +0 -13
  76. package/distTs/src/command/vt/close.js +0 -27
  77. package/distTs/src/command/vt/compare/validation.js +0 -173
  78. package/distTs/src/command/vt/compare.js +0 -97
  79. package/distTs/src/command/vt/exec.js +0 -81
  80. package/distTs/src/command/vt/installBrowser.js +0 -20
  81. package/distTs/src/command/vt/scrap.js +0 -193
  82. package/distTs/src/command/vt/storybook.js +0 -92
  83. package/distTs/src/command/vt.js +0 -22
  84. package/distTs/src/format.js +0 -174
  85. package/distTs/src/index.js +0 -34
  86. package/distTs/src/input.js +0 -270
  87. package/distTs/src/logger.js +0 -95
  88. package/distTs/src/output/interactive/tunnel.js +0 -860
  89. package/distTs/src/output/noninteractive/agent/tunnels.js +0 -43
  90. package/distTs/src/output/noninteractive/config/tunnel.js +0 -65
  91. package/distTs/src/output/noninteractive/config/tunnels.js +0 -18
  92. package/distTs/src/output/noninteractive/tunnel.js +0 -59
  93. package/distTs/src/output.js +0 -143
  94. package/distTs/src/server/cert.js +0 -52
  95. package/distTs/src/server/http1.js +0 -75
  96. package/distTs/src/server/http2.js +0 -78
  97. package/distTs/src/server/sftp.js +0 -497
  98. package/distTs/src/server/ssh.js +0 -446
  99. package/distTs/src/server/tls.js +0 -41
  100. package/distTs/src/ssh/client.js +0 -197
  101. package/distTs/src/texts.js +0 -421
  102. package/distTs/src/tunnel/agent.js +0 -103
  103. package/distTs/src/tunnel/api/agent.js +0 -100
  104. package/distTs/src/tunnel/api/buddy.js +0 -141
  105. package/distTs/src/tunnel/cfg.js +0 -243
  106. package/distTs/src/tunnel/compression.js +0 -44
  107. package/distTs/src/tunnel/dns.js +0 -53
  108. package/distTs/src/tunnel/html/503.html +0 -338
  109. package/distTs/src/tunnel/html.js +0 -33
  110. package/distTs/src/tunnel/http/log.js +0 -218
  111. package/distTs/src/tunnel/http/serve.js +0 -133
  112. package/distTs/src/tunnel/http/stream.js +0 -34
  113. package/distTs/src/tunnel/http.js +0 -508
  114. package/distTs/src/tunnel/identification.js +0 -103
  115. package/distTs/src/tunnel/latency.js +0 -83
  116. package/distTs/src/tunnel/output/interactive/tunnel.js +0 -867
  117. package/distTs/src/tunnel/output/noninteractive/agent/tunnels.js +0 -45
  118. package/distTs/src/tunnel/output/noninteractive/config/tunnel.js +0 -67
  119. package/distTs/src/tunnel/output/noninteractive/config/tunnels.js +0 -20
  120. package/distTs/src/tunnel/output/noninteractive/tunnel.js +0 -61
  121. package/distTs/src/tunnel/server/cert.js +0 -54
  122. package/distTs/src/tunnel/server/http1.js +0 -80
  123. package/distTs/src/tunnel/server/http2.js +0 -84
  124. package/distTs/src/tunnel/server/sftp.js +0 -514
  125. package/distTs/src/tunnel/server/ssh.js +0 -464
  126. package/distTs/src/tunnel/server/tls.js +0 -47
  127. package/distTs/src/tunnel/ssh/client.js +0 -211
  128. package/distTs/src/tunnel/tcp.js +0 -113
  129. package/distTs/src/tunnel/tunnel.js +0 -1010
  130. package/distTs/src/tunnel.js +0 -656
  131. package/distTs/src/types/ciInfo.js +0 -10
  132. package/distTs/src/types/options.js +0 -2
  133. package/distTs/src/types/plugin.js +0 -2
  134. package/distTs/src/types/queue.js +0 -2
  135. package/distTs/src/types/requests.js +0 -2
  136. package/distTs/src/types/resources.js +0 -2
  137. package/distTs/src/types/schemas.js +0 -54
  138. package/distTs/src/types/scrape.js +0 -2
  139. package/distTs/src/types/snapshots.js +0 -2
  140. package/distTs/src/types/storybook.js +0 -2
  141. package/distTs/src/types/tunnel.js +0 -141
  142. package/distTs/src/unitTest/ci.js +0 -108
  143. package/distTs/src/unitTest/requests.js +0 -72
  144. package/distTs/src/utils.js +0 -378
  145. package/distTs/src/visualTest/browser.js +0 -39
  146. package/distTs/src/visualTest/ci.js +0 -241
  147. package/distTs/src/visualTest/context.js +0 -52
  148. package/distTs/src/visualTest/exec.js +0 -51
  149. package/distTs/src/visualTest/linkUtils.js +0 -21
  150. package/distTs/src/visualTest/queue.js +0 -43
  151. package/distTs/src/visualTest/requests.js +0 -365
  152. package/distTs/src/visualTest/resources.js +0 -259
  153. package/distTs/src/visualTest/server.js +0 -109
  154. package/distTs/src/visualTest/snapshots.js +0 -129
  155. package/distTs/src/visualTest/utils/parseDom.js +0 -238
  156. package/distTs/src/visualTest/validation.js +0 -18
@@ -1,508 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const events_1 = __importDefault(require("events"));
7
- const uuid_1 = require("uuid");
8
- const http_1 = __importDefault(require("http"));
9
- const utils_1 = require("../utils");
10
- const stream_1 = __importDefault(require("stream"));
11
- const texts_1 = require("../texts");
12
- const logger_1 = __importDefault(require("../logger"));
13
- const serve_1 = __importDefault(require("./http/serve"));
14
- const https_1 = __importDefault(require("https"));
15
- const compression_1 = __importDefault(require("./compression"));
16
- const html_1 = __importDefault(require("./html"));
17
- const agent_1 = __importDefault(require("./agent"));
18
- const punycode_1 = __importDefault(require("punycode/"));
19
- const tunnel_1 = require("../types/tunnel");
20
- class TunnelHttp extends events_1.default {
21
- id;
22
- req;
23
- res;
24
- proto;
25
- host;
26
- port;
27
- hostHeader;
28
- serve;
29
- timeout;
30
- httpIdentify;
31
- verify;
32
- compression;
33
- headers;
34
- responseHeaders;
35
- httpLog;
36
- logRequest;
37
- auth;
38
- proxyRes;
39
- proxyReq;
40
- constructor({ req, res, proto, host, port, hostHeader, serve, timeout, httpIdentify, verify, httpLog, compression, headers, responseHeaders, auth = null, }) {
41
- super();
42
- this.id = (0, uuid_1.v4)();
43
- this.host = host;
44
- this.port = port;
45
- this.proto = proto;
46
- this.auth = auth;
47
- this.req = req;
48
- this.res = res;
49
- this.hostHeader = hostHeader;
50
- this.timeout = timeout || utils_1.DEFAULT_TIMEOUT;
51
- this.httpIdentify = httpIdentify;
52
- this.verify = verify;
53
- this.compression = compression;
54
- this.headers = {};
55
- this.responseHeaders = {};
56
- this.serve = serve;
57
- if (responseHeaders) {
58
- responseHeaders.forEach((header) => {
59
- this.responseHeaders[header.name.toLowerCase()] = header.value;
60
- });
61
- }
62
- if (headers) {
63
- headers.forEach((header) => {
64
- this.headers[header.name.toLowerCase()] = header.value;
65
- });
66
- }
67
- this.httpLog = httpLog;
68
- this.logRequest = null;
69
- }
70
- outputEnd(code, html) {
71
- try {
72
- if (this.logRequest) {
73
- const s = new stream_1.default.Readable();
74
- s.push(html);
75
- s.push(null);
76
- s.pipe(this.logRequest.responseBody);
77
- }
78
- if (this.httpLog)
79
- this.httpLog.newResponse(code, {}, this.logRequest);
80
- this.res.statusCode = code;
81
- this.res.end(html);
82
- }
83
- catch {
84
- // do nothing
85
- }
86
- this.clear();
87
- }
88
- getDisplayTarget() {
89
- let t = `${this.proto}://${this.host}`;
90
- if (this.proto === 'http' && this.port !== 80)
91
- t += `:${this.port}`;
92
- else if (this.proto === 'https' && this.port !== 443)
93
- t += `:${this.port}`;
94
- return t;
95
- }
96
- output504() {
97
- this.outputEnd(504, html_1.default.get504(this.getDisplayTarget()));
98
- }
99
- outputHeaders(statusCode, headers) {
100
- this.res.statusCode = statusCode;
101
- Object.keys(headers).forEach((name) => {
102
- this.res.setHeader(name.toLowerCase(), headers[name]);
103
- });
104
- Object.keys(this.responseHeaders).forEach((name) => {
105
- this.res.setHeader(name.toLowerCase(), this.responseHeaders[name]);
106
- });
107
- }
108
- getHostHeader() {
109
- if (this.hostHeader)
110
- return punycode_1.default.toASCII(this.hostHeader);
111
- let h = this.host || '';
112
- if (this.proto === 'http' && this.port !== 80)
113
- h += `:${this.port}`;
114
- else if (this.proto === 'https' && this.port !== 443)
115
- h += `:${this.port}`;
116
- return punycode_1.default.toASCII(h);
117
- }
118
- getForwardedHost() {
119
- if (this.req.headers.host)
120
- return this.req.headers.host;
121
- if (this.req.headers[':authority'])
122
- return this.req.headers[':authority'];
123
- return 'localhost';
124
- }
125
- getRequestHeaders(http2) {
126
- const h = {};
127
- let ip;
128
- if (this.req.httpVersion === '2.0') {
129
- ip = this.req.socket.stream
130
- ? this.req.socket.stream.remoteAddress
131
- : '::1';
132
- }
133
- else {
134
- ip = this.req.socket.remoteAddress;
135
- }
136
- if (http2) {
137
- h[':scheme'] = this.proto || '';
138
- h[':authority'] = this.getHostHeader();
139
- h[':method'] = this.getMethod();
140
- h[':path'] = this.getPath();
141
- }
142
- else {
143
- h.host = this.getHostHeader();
144
- }
145
- h['x-forwarded-for'] = ip || '0.0.0.0';
146
- h['x-forwarded-proto'] = 'https';
147
- h['x-forwarded-host'] = this.getForwardedHost();
148
- if (this.auth) {
149
- h['authorization'] = `Basic ${Buffer.from(this.auth).toString('base64')}`;
150
- }
151
- return h;
152
- }
153
- getClearedHeaders(headers = {}, compressionMethod, allowUpgrade = false) {
154
- const hop = [
155
- ':method',
156
- ':path',
157
- ':scheme',
158
- ':authority',
159
- ':status',
160
- 'host',
161
- 'proxy-authenticate',
162
- 'proxy-connection',
163
- 'proxy-authorization',
164
- 'trailer',
165
- 'transfer-encoding',
166
- 'strict-transport-security',
167
- 'te',
168
- ];
169
- if (!(allowUpgrade && headers.connection === 'Upgrade')) {
170
- hop.push('upgrade');
171
- hop.push('connection');
172
- hop.push('keep-alive');
173
- }
174
- const tmp = {};
175
- if (compressionMethod &&
176
- compressionMethod !== tunnel_1.TUNNEL_COMPRESSION_METHOD.IDENTITY) {
177
- tmp['content-encoding'] = compressionMethod;
178
- hop.push('content-length');
179
- hop.push('content-encoding');
180
- }
181
- Object.keys(headers).forEach((name) => {
182
- if (!hop.includes(name)) {
183
- tmp[name] = headers[name];
184
- }
185
- });
186
- tmp['access-control-allow-origin'] = '*';
187
- if (tmp['set-cookie']) {
188
- const setCookie = [];
189
- const h = (this.req.headers.host ||
190
- this.req.headers[':authority'] ||
191
- '').split(':')[0];
192
- tmp['set-cookie'].forEach((cookie) => {
193
- setCookie.push(cookie.replaceAll(/([dD]omain)=[\w_\-\\.]+/gi, `$1=${h}`));
194
- });
195
- tmp['set-cookie'] = setCookie;
196
- }
197
- return tmp;
198
- }
199
- getPath() {
200
- const { pathname, search } = new URL(this.req.url, 'http://a.b');
201
- let path = pathname;
202
- if (search)
203
- path += search;
204
- return path;
205
- }
206
- getMethod() {
207
- return this.req.method;
208
- }
209
- createRequestHttp1() {
210
- const reqHeaders = this.req.headers;
211
- const method = this.getMethod();
212
- const path = this.getPath();
213
- const headers = {
214
- ...this.getClearedHeaders(reqHeaders, null, true),
215
- ...this.headers,
216
- ...this.getRequestHeaders(false),
217
- };
218
- const r = http_1.default.request({
219
- agent: agent_1.default.getHttp1(),
220
- host: (0, utils_1.getRealTargetHost)(this.host),
221
- port: this.port,
222
- method,
223
- protocol: 'http:',
224
- setHost: false,
225
- path,
226
- headers,
227
- });
228
- if (this.httpLog) {
229
- this.logRequest = this.httpLog.newRequest(method, headers, path, tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP1, this.req);
230
- }
231
- r.on('upgrade', (proxyRes, socket, head) => this.upgrade(proxyRes, socket, head));
232
- r.on('response', (proxyRes) => {
233
- this.proxyRes = proxyRes;
234
- const statusCode = this.proxyRes.statusCode;
235
- const resHeaders = this.proxyRes.headers;
236
- const compressionMethod = compression_1.default.detect(this.compression || false, reqHeaders, resHeaders);
237
- this.outputHeaders(statusCode, this.getClearedHeaders(resHeaders, compressionMethod));
238
- if (this.logRequest) {
239
- this.proxyRes
240
- .pipe(this.logRequest.responseBody)
241
- .pipe(compression_1.default.compress(compressionMethod))
242
- .pipe(this.res);
243
- }
244
- else {
245
- this.proxyRes
246
- .pipe(compression_1.default.compress(compressionMethod))
247
- .pipe(this.res);
248
- }
249
- if (this.httpLog) {
250
- this.httpLog.newResponse(statusCode, resHeaders, this.logRequest);
251
- }
252
- });
253
- return r;
254
- }
255
- createRequestHttps1() {
256
- const reqHeaders = this.req.headers;
257
- const method = this.getMethod();
258
- const headers = {
259
- ...this.getClearedHeaders(reqHeaders, null, true),
260
- ...this.headers,
261
- ...this.getRequestHeaders(false),
262
- };
263
- const path = this.getPath();
264
- const r = https_1.default.request({
265
- agent: agent_1.default.getHttps1(),
266
- host: (0, utils_1.getRealTargetHost)(this.host),
267
- port: this.port,
268
- method,
269
- protocol: 'https:',
270
- setHost: false,
271
- path,
272
- rejectUnauthorized: this.verify,
273
- headers,
274
- });
275
- if (this.httpLog) {
276
- this.logRequest = this.httpLog.newRequest(method, headers, path, tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP1, this.req);
277
- }
278
- r.on('upgrade', (proxyRes, socket, head) => this.upgrade(proxyRes, socket, head));
279
- r.on('response', (proxyRes) => {
280
- this.proxyRes = proxyRes;
281
- const statusCode = this.proxyRes.statusCode;
282
- const resHeaders = this.proxyRes.headers;
283
- const compressionMethod = compression_1.default.detect(this.compression || false, reqHeaders, resHeaders);
284
- this.outputHeaders(statusCode, this.getClearedHeaders(resHeaders, compressionMethod));
285
- if (this.logRequest) {
286
- this.proxyRes
287
- .pipe(this.logRequest.responseBody)
288
- .pipe(compression_1.default.compress(compressionMethod))
289
- .pipe(this.res);
290
- }
291
- else {
292
- this.proxyRes
293
- .pipe(compression_1.default.compress(compressionMethod))
294
- .pipe(this.res);
295
- }
296
- if (this.httpLog) {
297
- this.httpLog.newResponse(statusCode, resHeaders, this.logRequest);
298
- }
299
- });
300
- return r;
301
- }
302
- createServe() {
303
- const reqHeaders = this.req.headers;
304
- const r = new serve_1.default(this.serve || '');
305
- const method = this.getMethod();
306
- const path = this.getPath();
307
- if (this.httpLog) {
308
- this.logRequest = this.httpLog.newRequest(method, reqHeaders, path, tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP1, this.req);
309
- }
310
- r.on('response', (statusCode, resHeaders, stream) => {
311
- if (!stream) {
312
- this.outputHeaders(statusCode, this.getClearedHeaders(resHeaders));
313
- this.res.end();
314
- }
315
- else {
316
- const compressionMethod = compression_1.default.detect(this.compression || false, reqHeaders, resHeaders);
317
- this.outputHeaders(statusCode, this.getClearedHeaders(resHeaders, compressionMethod));
318
- if (this.logRequest) {
319
- stream
320
- .pipe(this.logRequest.responseBody)
321
- .pipe(compression_1.default.compress(compressionMethod))
322
- .pipe(this.res);
323
- }
324
- else {
325
- stream
326
- .pipe(compression_1.default.compress(compressionMethod))
327
- .pipe(this.res);
328
- }
329
- }
330
- if (this.httpLog) {
331
- this.httpLog.newResponse(statusCode, resHeaders, this.logRequest);
332
- }
333
- });
334
- return r;
335
- }
336
- async createRequestHttps2() {
337
- const reqHeaders = this.req.headers;
338
- const authority = `${this.proto}://${(0, utils_1.getRealTargetHost)(this.host)}:${this.port}`;
339
- const client = await agent_1.default.getHttp2Client(authority, this.host || '', this.verify || false);
340
- const method = this.getMethod();
341
- const path = this.getPath();
342
- const headers = {
343
- ...this.getClearedHeaders(reqHeaders),
344
- ...this.headers,
345
- ...this.getRequestHeaders(true),
346
- };
347
- const r = client.request(headers);
348
- if (this.httpLog) {
349
- this.logRequest = this.httpLog.newRequest(method, headers, path, tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP2, this.req);
350
- }
351
- r.on('response', (resHeaders) => {
352
- const status = resHeaders[':status'] || 200;
353
- const compressionMethod = compression_1.default.detect(this.compression || false, reqHeaders, resHeaders);
354
- this.outputHeaders(status, this.getClearedHeaders(resHeaders, compressionMethod));
355
- if (this.logRequest) {
356
- r.pipe(this.logRequest.responseBody)
357
- .pipe(compression_1.default.compress(compressionMethod))
358
- .pipe(this.res);
359
- }
360
- else {
361
- r.pipe(compression_1.default.compress(compressionMethod)).pipe(this.res);
362
- }
363
- if (this.httpLog) {
364
- this.httpLog.newResponse(status, resHeaders, this.logRequest);
365
- }
366
- });
367
- return r;
368
- }
369
- async createRequest() {
370
- if (this.httpIdentify === tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP1) {
371
- if (this.proto === 'http')
372
- return this.createRequestHttp1();
373
- return this.createRequestHttps1();
374
- }
375
- return this.createRequestHttps2();
376
- }
377
- clear() {
378
- if (this.req) {
379
- this.req.removeAllListeners();
380
- this.req = null;
381
- }
382
- if (this.res) {
383
- this.res.removeAllListeners();
384
- this.res = null;
385
- }
386
- if (this.proxyReq) {
387
- this.proxyReq.removeAllListeners();
388
- this.proxyReq = null;
389
- }
390
- if (this.proxyRes) {
391
- this.proxyRes.removeAllListeners();
392
- this.proxyRes = null;
393
- }
394
- if (this.httpLog) {
395
- this.httpLog = null;
396
- }
397
- if (this.logRequest) {
398
- this.logRequest.removeAllListeners();
399
- this.logRequest = null;
400
- }
401
- }
402
- upgrade(proxyRes, socket, head) {
403
- const resHeaders = proxyRes?.headers || {};
404
- const reqSocket = this.req.socket;
405
- if (this.httpLog) {
406
- this.httpLog.newResponse(101, resHeaders, this.logRequest);
407
- }
408
- socket.setTimeout(0);
409
- const headers = this.getClearedHeaders(resHeaders, null, true);
410
- this.clear();
411
- let msg = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n';
412
- Object.keys(headers).forEach((k) => {
413
- const v = headers[k];
414
- if (Array.isArray(v)) {
415
- v.forEach((vv) => {
416
- msg += `${k}: ${vv}\r\n`;
417
- });
418
- }
419
- else {
420
- msg += `${k}: ${v}\r\n`;
421
- }
422
- });
423
- msg += '\r\n';
424
- reqSocket.removeAllListeners();
425
- socket.removeAllListeners();
426
- reqSocket.on('close', () => {
427
- reqSocket.removeAllListeners();
428
- this.emit(tunnel_1.TUNNEL_HTTP_SOCKET.CLOSED, reqSocket);
429
- });
430
- socket.on('close', () => {
431
- socket.removeAllListeners();
432
- try {
433
- reqSocket.destroy();
434
- }
435
- catch {
436
- // do nothing
437
- }
438
- });
439
- if (head && head.length) {
440
- socket.unshift(head);
441
- }
442
- reqSocket.write(msg);
443
- reqSocket.pipe(socket).pipe(reqSocket);
444
- }
445
- async pipe() {
446
- if (this.serve) {
447
- try {
448
- this.proxyReq = this.createServe();
449
- }
450
- catch (err) {
451
- logger_1.default.debug(texts_1.LOG_ERROR);
452
- logger_1.default.debug(err);
453
- this.output504();
454
- return;
455
- }
456
- this.proxyReq.on('error', () => {
457
- this.output504();
458
- });
459
- this.proxyReq.on('close', () => {
460
- setTimeout(() => {
461
- this.clear();
462
- }, 5000);
463
- });
464
- this.proxyReq.process(this.req);
465
- }
466
- else {
467
- try {
468
- this.proxyReq = await this.createRequest();
469
- }
470
- catch (err) {
471
- logger_1.default.debug(texts_1.LOG_ERROR);
472
- logger_1.default.debug(err);
473
- if (this.logRequest) {
474
- this.req.pipe(this.logRequest.requestBody);
475
- // no real request waiting for this data -> push it into the void
476
- this.logRequest.requestBody.pipeToNothing(() => {
477
- // wait for piping request
478
- this.output504();
479
- });
480
- return;
481
- }
482
- this.output504();
483
- return;
484
- }
485
- this.proxyReq.setTimeout(this.timeout * 1000);
486
- this.proxyReq.on('timeout', () => {
487
- this.output504();
488
- });
489
- this.proxyReq.on('error', (err) => {
490
- logger_1.default.debug(texts_1.LOG_ERROR);
491
- logger_1.default.debug(err);
492
- this.output504();
493
- });
494
- this.proxyReq.on('close', () => {
495
- setTimeout(() => {
496
- this.clear();
497
- }, 5000);
498
- });
499
- if (this.logRequest) {
500
- this.req.pipe(this.logRequest.requestBody).pipe(this.proxyReq);
501
- }
502
- else {
503
- this.req.pipe(this.proxyReq);
504
- }
505
- }
506
- }
507
- }
508
- exports.default = TunnelHttp;
@@ -1,103 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const events_1 = __importDefault(require("events"));
7
- const tls_1 = __importDefault(require("tls"));
8
- const net_1 = __importDefault(require("net"));
9
- const utils_1 = require("../utils");
10
- const tunnel_1 = require("../types/tunnel");
11
- const CHECK_INTERVAL = 300000;
12
- const CHECK_TIMEOUT = 5000;
13
- class TunnelIdentification extends events_1.default {
14
- proto;
15
- host;
16
- port;
17
- forceHttp2;
18
- type;
19
- ts;
20
- constructor(proto, host, port, forceHttp2) {
21
- super();
22
- this.proto = proto;
23
- this.host = (0, utils_1.getRealTargetHost)(host);
24
- this.port = port;
25
- this.forceHttp2 = forceHttp2;
26
- this.type = tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP1;
27
- this.identify();
28
- this.ts = setInterval(() => this.identify(), CHECK_INTERVAL);
29
- }
30
- stop() {
31
- if (this.ts) {
32
- clearInterval(this.ts);
33
- this.ts = null;
34
- }
35
- }
36
- identify() {
37
- if (this.forceHttp2) {
38
- this.type = tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP2;
39
- this.emit(tunnel_1.TUNNEL_EVENT.IDENTIFIED, tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP2);
40
- return;
41
- }
42
- let socket;
43
- const close = () => {
44
- try {
45
- socket.removeAllListeners();
46
- socket.end();
47
- socket.destroy();
48
- }
49
- catch {
50
- // do nothing
51
- }
52
- };
53
- const connected = () => {
54
- if (socket instanceof tls_1.default.TLSSocket && socket.alpnProtocol) {
55
- if (socket.alpnProtocol === 'h2') {
56
- this.type = tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP2;
57
- this.emit(tunnel_1.TUNNEL_EVENT.IDENTIFIED, tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP2);
58
- }
59
- else {
60
- this.type = tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP1;
61
- this.emit(tunnel_1.TUNNEL_EVENT.IDENTIFIED, tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP1);
62
- }
63
- close();
64
- }
65
- else {
66
- socket.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n');
67
- socket.on('data', (d) => {
68
- if (/HTTP\/1/.test(d.toString('utf8'))) {
69
- this.type = tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP1;
70
- this.emit(tunnel_1.TUNNEL_EVENT.IDENTIFIED, tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP1);
71
- }
72
- else {
73
- this.type = tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP2;
74
- this.emit(tunnel_1.TUNNEL_EVENT.IDENTIFIED, tunnel_1.TUNNEL_HTTP_IDENTIFY.HTTP2);
75
- }
76
- close();
77
- });
78
- }
79
- };
80
- if (this.proto === 'http') {
81
- socket = net_1.default.connect({
82
- host: this.host,
83
- port: this.port,
84
- });
85
- socket.on('connect', connected);
86
- }
87
- else {
88
- socket = tls_1.default.connect({
89
- host: this.host,
90
- port: this.port,
91
- rejectUnauthorized: true,
92
- ALPNProtocols: ['h2', 'http/1.1'],
93
- servername: this.host,
94
- });
95
- socket.on('secureConnect', connected);
96
- }
97
- socket.setTimeout(CHECK_TIMEOUT);
98
- socket.on('timeout', close);
99
- socket.on('error', close);
100
- socket.on('close', close);
101
- }
102
- }
103
- exports.default = TunnelIdentification;
@@ -1,83 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const net_1 = require("net");
7
- const events_1 = __importDefault(require("events"));
8
- const utils_1 = require("../utils");
9
- const tunnel_1 = require("../types/tunnel");
10
- class TunnelLatency extends events_1.default {
11
- latency;
12
- isChecking;
13
- port;
14
- host;
15
- ts;
16
- constructor(host, port) {
17
- super();
18
- this.latency = -1;
19
- this.isChecking = false;
20
- this.port = port;
21
- this.host = (0, utils_1.getRealTargetHost)(host);
22
- this.ts = null;
23
- }
24
- check() {
25
- if (this.isChecking)
26
- return;
27
- if (!this.port || !this.host) {
28
- this.latency = -1;
29
- return;
30
- }
31
- this.isChecking = true;
32
- let socket = new net_1.Socket();
33
- let ts = null;
34
- const clear = () => {
35
- if (ts)
36
- clearTimeout(ts);
37
- if (socket) {
38
- try {
39
- socket.removeAllListeners();
40
- socket.once('error', () => { });
41
- socket.end();
42
- socket.destroy();
43
- }
44
- catch {
45
- // do nothing
46
- }
47
- }
48
- socket = null;
49
- this.isChecking = false;
50
- };
51
- ts = setTimeout(() => {
52
- this.latency = -1;
53
- clear();
54
- }, 30000);
55
- const start = process.hrtime();
56
- socket.on('error', () => {
57
- this.latency = -1;
58
- clear();
59
- });
60
- socket.on('ready', () => {
61
- const elapsed = process.hrtime(start);
62
- if (this.latency < 0)
63
- this.emit(tunnel_1.TUNNEL_EVENT_LATENCY.RECONNECTED);
64
- this.latency = elapsed[0] * 1000 + elapsed[1] / 1000000; // ms
65
- clear();
66
- });
67
- socket.connect(this.port, this.host);
68
- }
69
- startChecking() {
70
- this.check();
71
- this.stopChecking();
72
- this.ts = setInterval(() => {
73
- this.check();
74
- }, 3000);
75
- }
76
- stopChecking() {
77
- if (this.ts) {
78
- clearInterval(this.ts);
79
- this.ts = null;
80
- }
81
- }
82
- }
83
- exports.default = TunnelLatency;