bdy 1.10.14-stage → 1.11.0-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.
Files changed (100) hide show
  1. package/distTs/bin/cli.js +1 -1
  2. package/distTs/package.json +1 -1
  3. package/distTs/src/agent/agent.js +302 -0
  4. package/distTs/src/agent/manager.js +41 -41
  5. package/distTs/src/agent/socket/client.js +159 -0
  6. package/distTs/src/agent/socket/tunnel.js +3 -3
  7. package/distTs/src/agent/wait.js +2 -2
  8. package/distTs/src/command/agent/disable.js +1 -1
  9. package/distTs/src/command/agent/enable.js +1 -1
  10. package/distTs/src/command/agent/install.js +45 -45
  11. package/distTs/src/command/agent/restart.js +8 -8
  12. package/distTs/src/command/agent/start.js +8 -8
  13. package/distTs/src/command/agent/status.js +15 -15
  14. package/distTs/src/command/agent/stop.js +8 -8
  15. package/distTs/src/command/agent/target/disable.js +1 -1
  16. package/distTs/src/command/agent/target/enable.js +1 -1
  17. package/distTs/src/command/agent/target/status.js +1 -1
  18. package/distTs/src/command/agent/tunnel/http.js +18 -18
  19. package/distTs/src/command/agent/tunnel/list.js +7 -7
  20. package/distTs/src/command/agent/tunnel/remove.js +9 -9
  21. package/distTs/src/command/agent/tunnel/start.js +14 -14
  22. package/distTs/src/command/agent/tunnel/status.js +11 -11
  23. package/distTs/src/command/agent/tunnel/tcp.js +19 -19
  24. package/distTs/src/command/agent/tunnel/tls.js +17 -17
  25. package/distTs/src/command/agent/tunnel.js +16 -16
  26. package/distTs/src/command/agent/uninstall.js +13 -13
  27. package/distTs/src/command/agent/update.js +12 -12
  28. package/distTs/src/command/agent/version.js +6 -6
  29. package/distTs/src/command/agent.js +18 -18
  30. package/distTs/src/command/config/add/http.js +15 -15
  31. package/distTs/src/command/config/add/tcp.js +15 -15
  32. package/distTs/src/command/config/add/tls.js +15 -15
  33. package/distTs/src/command/config/add.js +8 -8
  34. package/distTs/src/command/config/get/region.js +5 -5
  35. package/distTs/src/command/config/get/timeout.js +5 -5
  36. package/distTs/src/command/config/get/token.js +5 -5
  37. package/distTs/src/command/config/get/tunnel.js +9 -9
  38. package/distTs/src/command/config/get/tunnels.js +6 -6
  39. package/distTs/src/command/config/get/whitelist.js +5 -5
  40. package/distTs/src/command/config/get.js +14 -14
  41. package/distTs/src/command/config/remove/tunnel.js +9 -9
  42. package/distTs/src/command/config/remove.js +4 -4
  43. package/distTs/src/command/config/set/region.js +8 -8
  44. package/distTs/src/command/config/set/timeout.js +9 -9
  45. package/distTs/src/command/config/set/token.js +7 -7
  46. package/distTs/src/command/config/set/whitelist.js +8 -8
  47. package/distTs/src/command/config/set.js +10 -10
  48. package/distTs/src/command/pre.js +14 -14
  49. package/distTs/src/command/tunnel/config.js +17 -0
  50. package/distTs/src/command/tunnel/http.js +30 -0
  51. package/distTs/src/command/tunnel/start.js +28 -0
  52. package/distTs/src/command/tunnel/tcp.js +30 -0
  53. package/distTs/src/command/tunnel/tls.js +30 -0
  54. package/distTs/src/command/tunnel.js +19 -0
  55. package/distTs/src/command/ut/upload.js +6 -6
  56. package/distTs/src/command/ut.js +3 -2
  57. package/distTs/src/command/version.js +4 -4
  58. package/distTs/src/command/vt/close.js +4 -4
  59. package/distTs/src/command/vt/compare.js +16 -16
  60. package/distTs/src/command/vt/exec.js +12 -12
  61. package/distTs/src/command/vt/installBrowser.js +2 -2
  62. package/distTs/src/command/vt/scrap.js +17 -17
  63. package/distTs/src/command/vt/storybook.js +8 -8
  64. package/distTs/src/command/vt.js +5 -4
  65. package/distTs/src/index.js +12 -20
  66. package/distTs/src/input.js +38 -38
  67. package/distTs/src/logger.js +2 -2
  68. package/distTs/src/output.js +14 -14
  69. package/distTs/src/texts.js +5 -4
  70. package/distTs/src/tunnel/agent.js +3 -3
  71. package/distTs/src/tunnel/api/agent.js +99 -0
  72. package/distTs/src/tunnel/api/buddy.js +139 -0
  73. package/distTs/src/tunnel/cfg.js +234 -0
  74. package/distTs/src/tunnel/http/log.js +3 -3
  75. package/distTs/src/tunnel/http.js +29 -29
  76. package/distTs/src/tunnel/identification.js +13 -13
  77. package/distTs/src/tunnel/latency.js +3 -3
  78. package/distTs/src/tunnel/output/interactive/tunnel.js +860 -0
  79. package/distTs/src/tunnel/output/noninteractive/agent/tunnels.js +43 -0
  80. package/distTs/src/tunnel/output/noninteractive/config/tunnel.js +65 -0
  81. package/distTs/src/tunnel/output/noninteractive/config/tunnels.js +18 -0
  82. package/distTs/src/tunnel/output/noninteractive/tunnel.js +59 -0
  83. package/distTs/src/tunnel/server/cert.js +52 -0
  84. package/distTs/src/tunnel/server/http1.js +75 -0
  85. package/distTs/src/tunnel/server/http2.js +78 -0
  86. package/distTs/src/tunnel/server/sftp.js +497 -0
  87. package/distTs/src/tunnel/server/ssh.js +446 -0
  88. package/distTs/src/tunnel/server/tls.js +41 -0
  89. package/distTs/src/tunnel/ssh/client.js +197 -0
  90. package/distTs/src/tunnel/tcp.js +3 -3
  91. package/distTs/src/tunnel/tunnel.js +656 -0
  92. package/distTs/src/utils.js +2 -2
  93. package/distTs/src/visualTest/ci.js +10 -10
  94. package/distTs/src/visualTest/context.js +4 -4
  95. package/distTs/src/visualTest/requests.js +71 -71
  96. package/distTs/src/visualTest/resources.js +5 -5
  97. package/distTs/src/visualTest/server.js +9 -9
  98. package/distTs/src/visualTest/snapshots.js +18 -18
  99. package/distTs/src/visualTest/validation.js +3 -3
  100. package/package.json +1 -1
@@ -0,0 +1,234 @@
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 path_1 = require("path");
7
+ const fs_1 = require("fs");
8
+ const jsonwebtoken_1 = require("jsonwebtoken");
9
+ const utils_1 = require("../utils");
10
+ const input_1 = __importDefault(require("../input"));
11
+ const texts_1 = require("../texts");
12
+ class Cfg {
13
+ constructor() {
14
+ this.dir = (0, utils_1.getHomeDirectory)();
15
+ this.file = (0, path_1.resolve)(this.dir, 'cfg.json');
16
+ this.json = {};
17
+ this.load();
18
+ }
19
+ createDir() {
20
+ try {
21
+ (0, fs_1.mkdirSync)(this.dir, {
22
+ recursive: true,
23
+ });
24
+ }
25
+ catch {
26
+ throw new Error((0, texts_1.ERR_CANT_CREATE_DIR_IN_HOME)('.bdy'));
27
+ }
28
+ try {
29
+ (0, fs_1.chmodSync)(this.dir, 0o777);
30
+ }
31
+ catch {
32
+ // do nothing
33
+ }
34
+ }
35
+ createEmptyFile() {
36
+ try {
37
+ (0, fs_1.writeFileSync)(this.file, '{}', 'utf-8');
38
+ }
39
+ catch {
40
+ throw new Error((0, texts_1.ERR_CANT_CREATE_DIR_IN_HOME)('.bdy/cfg.json'));
41
+ }
42
+ try {
43
+ (0, fs_1.chmodSync)(this.file, 0o666);
44
+ }
45
+ catch {
46
+ // do nothing
47
+ }
48
+ }
49
+ ensureDir() {
50
+ try {
51
+ (0, fs_1.statSync)(this.dir);
52
+ }
53
+ catch {
54
+ this.createDir();
55
+ }
56
+ }
57
+ ensureFile() {
58
+ this.ensureDir();
59
+ try {
60
+ (0, fs_1.statSync)(this.file);
61
+ }
62
+ catch {
63
+ this.createEmptyFile();
64
+ }
65
+ }
66
+ ensureTunnels() {
67
+ if (!this.json.tunnels)
68
+ this.json.tunnels = {};
69
+ }
70
+ async prepareTunnel(tunnelType, target, options, useDefaults) {
71
+ const type = input_1.default.type(tunnelType);
72
+ const tunnel = {
73
+ type,
74
+ target: input_1.default.target(target, type),
75
+ };
76
+ if (options.region !== undefined)
77
+ tunnel.region = input_1.default.region(options.region);
78
+ else if (useDefaults)
79
+ tunnel.region = this.getRegion();
80
+ if (options.whitelist !== undefined)
81
+ tunnel.whitelist = input_1.default.whitelist(options.whitelist);
82
+ else if (useDefaults)
83
+ tunnel.whitelist = this.getWhitelist();
84
+ if (options.timeout !== undefined)
85
+ tunnel.timeout = input_1.default.timeout(options.timeout);
86
+ else if (useDefaults)
87
+ tunnel.timeout = this.getTimeout();
88
+ if (type === utils_1.TUNNEL_HTTP) {
89
+ if (options.host !== undefined)
90
+ tunnel.host = options.host;
91
+ if (options.auth !== undefined) {
92
+ const { password, login } = input_1.default.auth(options.auth);
93
+ tunnel.login = login;
94
+ tunnel.password = password;
95
+ }
96
+ if (options.ca !== undefined)
97
+ tunnel.ca = input_1.default.ca(options.ca);
98
+ if (options.serve !== undefined)
99
+ tunnel.serve = input_1.default.serve(options.serve);
100
+ if (options.useragent !== undefined)
101
+ tunnel.useragents = input_1.default.useragents(options.useragent);
102
+ if (options.header !== undefined)
103
+ tunnel.headers = input_1.default.headers(options.header);
104
+ if (options.responseHeader !== undefined)
105
+ tunnel.responseHeaders = input_1.default.headers(options.responseHeader);
106
+ if (options.circuitBreaker !== undefined)
107
+ tunnel.circuitBreaker = input_1.default.circuitBreaker(options.circuitBreaker);
108
+ tunnel.log = !!options.log;
109
+ tunnel.verify = !!options.verify;
110
+ tunnel.http2 = !!options.http2;
111
+ tunnel.compression = !!options.compression;
112
+ }
113
+ else if (type === utils_1.TUNNEL_TLS) {
114
+ tunnel.terminate = input_1.default.terminate(options.terminate);
115
+ if (options.key !== undefined || options.cert !== undefined) {
116
+ const { key, cert } = input_1.default.keyCert(options.key, options.cert);
117
+ tunnel.key = key;
118
+ tunnel.cert = cert;
119
+ }
120
+ if (options.ca !== undefined)
121
+ tunnel.ca = input_1.default.ca(options.ca);
122
+ }
123
+ if (options.name !== undefined)
124
+ tunnel.name = input_1.default.name(options.name);
125
+ return tunnel;
126
+ }
127
+ async addTunnel(name, type, target, options) {
128
+ this.ensureTunnels();
129
+ this.json.tunnels[name] = await this.prepareTunnel(type, target, {
130
+ name,
131
+ ...options,
132
+ }, false);
133
+ this.save();
134
+ }
135
+ removeTunnel(name) {
136
+ this.ensureTunnels();
137
+ delete this.json.tunnels[name];
138
+ this.save();
139
+ }
140
+ getTunnels() {
141
+ this.ensureTunnels();
142
+ return this.json.tunnels;
143
+ }
144
+ hasTunnel(name) {
145
+ this.ensureTunnels();
146
+ return !!this.json.tunnels[name];
147
+ }
148
+ getTunnel(name) {
149
+ this.ensureTunnels();
150
+ return this.json.tunnels[name];
151
+ }
152
+ setToken(token) {
153
+ if (!token)
154
+ delete this.json.token;
155
+ else
156
+ this.json.token = token;
157
+ this.save();
158
+ }
159
+ setWhitelist(whitelist) {
160
+ if (!whitelist || !whitelist.length)
161
+ delete this.json.whitelist;
162
+ else
163
+ this.json.whitelist = whitelist;
164
+ this.save();
165
+ }
166
+ setTimeout(timeout) {
167
+ if (!timeout)
168
+ delete this.json.timeout;
169
+ else
170
+ this.json.timeout = timeout;
171
+ this.save();
172
+ }
173
+ getToken() {
174
+ return this.json.token || '';
175
+ }
176
+ getTokenHost() {
177
+ const token = this.getToken();
178
+ if (!token) {
179
+ throw new Error(texts_1.ERR_TOKEN_NOT_PROVIDED);
180
+ }
181
+ const d = (0, jsonwebtoken_1.decode)(token);
182
+ if (d === null) {
183
+ throw new Error(texts_1.ERR_WRONG_TOKEN);
184
+ }
185
+ if (!d.host) {
186
+ throw new Error(texts_1.ERR_WRONG_TOKEN);
187
+ }
188
+ return d.host;
189
+ }
190
+ getRegion() {
191
+ return (this.json.region || '').toUpperCase();
192
+ }
193
+ getTimeout() {
194
+ return this.json.timeout || utils_1.DEFAULT_TIMEOUT;
195
+ }
196
+ getWhitelist() {
197
+ return this.json.whitelist || [];
198
+ }
199
+ setRegion(region) {
200
+ this.json.region = region;
201
+ this.save();
202
+ }
203
+ setRegionIfNotSet(region) {
204
+ if (!this.json.region && region)
205
+ this.json.region = region.toUpperCase();
206
+ this.save();
207
+ }
208
+ load() {
209
+ this.ensureFile();
210
+ try {
211
+ const txt = (0, fs_1.readFileSync)(this.file, 'utf-8');
212
+ this.json = JSON.parse(txt);
213
+ }
214
+ catch {
215
+ throw new Error(texts_1.ERR_CONFIG_CORRUPTED);
216
+ }
217
+ }
218
+ save() {
219
+ this.ensureDir();
220
+ try {
221
+ (0, fs_1.writeFileSync)(this.file, JSON.stringify(this.json, null, 4), 'utf-8');
222
+ }
223
+ catch {
224
+ throw new Error((0, texts_1.ERR_CANT_CREATE_DIR_IN_HOME)('.bdy/cfg.json'));
225
+ }
226
+ try {
227
+ (0, fs_1.chmodSync)(this.file, 0o666);
228
+ }
229
+ catch {
230
+ // do nothing
231
+ }
232
+ }
233
+ }
234
+ exports.default = new Cfg();
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const events_1 = __importDefault(require("events"));
7
7
  const uuid_1 = require("uuid");
8
- const stream_js_1 = __importDefault(require("./stream.js"));
8
+ const stream_1 = __importDefault(require("./stream"));
9
9
  const isbinaryfile_1 = require("isbinaryfile");
10
10
  const utils_1 = require("../../utils");
11
11
  class TunnelHttpLogRequest extends events_1.default {
@@ -19,11 +19,11 @@ class TunnelHttpLogRequest extends events_1.default {
19
19
  this.start = process.hrtime();
20
20
  this.finished = false;
21
21
  this.id = (0, uuid_1.v4)();
22
- this.requestBody = new stream_js_1.default(utils_1.TUNNEL_HTTP_LOG_MAX_BODY);
22
+ this.requestBody = new stream_1.default(utils_1.TUNNEL_HTTP_LOG_MAX_BODY);
23
23
  this.requestBody.once('close', () => {
24
24
  this.emit(utils_1.EVENT_TUNNEL_HTTP_NEW_REQUEST_END);
25
25
  });
26
- this.responseBody = new stream_js_1.default(utils_1.TUNNEL_HTTP_LOG_MAX_BODY);
26
+ this.responseBody = new stream_1.default(utils_1.TUNNEL_HTTP_LOG_MAX_BODY);
27
27
  this.responseBody.once('close', () => {
28
28
  this.emit(utils_1.EVENT_TUNNEL_HTTP_NEW_RESPONSE_END);
29
29
  });
@@ -8,13 +8,13 @@ const uuid_1 = require("uuid");
8
8
  const http_1 = __importDefault(require("http"));
9
9
  const utils_1 = require("../utils");
10
10
  const stream_1 = __importDefault(require("stream"));
11
- const texts_js_1 = require("../texts.js");
12
- const logger_js_1 = __importDefault(require("../logger.js"));
13
- const serve_js_1 = __importDefault(require("./http/serve.js"));
11
+ const texts_1 = require("../texts");
12
+ const logger_1 = __importDefault(require("../logger"));
13
+ const serve_1 = __importDefault(require("./http/serve"));
14
14
  const https_1 = __importDefault(require("https"));
15
- const compression_js_1 = __importDefault(require("./compression.js"));
16
- const html_js_1 = __importDefault(require("./html.js"));
17
- const agent_js_1 = __importDefault(require("./agent.js"));
15
+ const compression_1 = __importDefault(require("./compression"));
16
+ const html_1 = __importDefault(require("./html"));
17
+ const agent_1 = __importDefault(require("./agent"));
18
18
  const punycode_js_1 = __importDefault(require("punycode.js"));
19
19
  class TunnelHttp extends events_1.default {
20
20
  constructor({ req, res, proto, host, port, hostHeader, serve, timeout, httpIdentify, verify, httpLog, compression, headers, responseHeaders, auth = null, }) {
@@ -73,7 +73,7 @@ class TunnelHttp extends events_1.default {
73
73
  return t;
74
74
  }
75
75
  output504() {
76
- this.outputEnd(504, html_js_1.default.get504(this.getDisplayTarget()));
76
+ this.outputEnd(504, html_1.default.get504(this.getDisplayTarget()));
77
77
  }
78
78
  outputHeaders(statusCode, headers) {
79
79
  this.res.statusCode = statusCode;
@@ -193,7 +193,7 @@ class TunnelHttp extends events_1.default {
193
193
  ...this.getRequestHeaders(false),
194
194
  };
195
195
  const r = http_1.default.request({
196
- agent: agent_js_1.default.getHttp1(),
196
+ agent: agent_1.default.getHttp1(),
197
197
  host: (0, utils_1.getRealTargetHost)(this.host),
198
198
  port: this.port,
199
199
  method,
@@ -208,17 +208,17 @@ class TunnelHttp extends events_1.default {
208
208
  this.proxyRes = proxyRes;
209
209
  const statusCode = this.proxyRes.statusCode;
210
210
  const resHeaders = this.proxyRes.headers;
211
- const compressionMethod = compression_js_1.default.detect(this.compression, reqHeaders, resHeaders);
211
+ const compressionMethod = compression_1.default.detect(this.compression, reqHeaders, resHeaders);
212
212
  this.outputHeaders(statusCode, this.getClearedHeaders(resHeaders, compressionMethod));
213
213
  if (this.logRequest) {
214
214
  this.proxyRes
215
215
  .pipe(this.logRequest.responseBody)
216
- .pipe(compression_js_1.default.compress(compressionMethod))
216
+ .pipe(compression_1.default.compress(compressionMethod))
217
217
  .pipe(this.res);
218
218
  }
219
219
  else {
220
220
  this.proxyRes
221
- .pipe(compression_js_1.default.compress(compressionMethod))
221
+ .pipe(compression_1.default.compress(compressionMethod))
222
222
  .pipe(this.res);
223
223
  }
224
224
  this.httpLog.newResponse(this.req, statusCode, resHeaders, this.logRequest);
@@ -235,7 +235,7 @@ class TunnelHttp extends events_1.default {
235
235
  };
236
236
  const path = this.getPath();
237
237
  const r = https_1.default.request({
238
- agent: agent_js_1.default.getHttps1(),
238
+ agent: agent_1.default.getHttps1(),
239
239
  host: (0, utils_1.getRealTargetHost)(this.host),
240
240
  port: this.port,
241
241
  method,
@@ -251,17 +251,17 @@ class TunnelHttp extends events_1.default {
251
251
  this.proxyRes = proxyRes;
252
252
  const statusCode = this.proxyRes.statusCode;
253
253
  const resHeaders = this.proxyRes.headers;
254
- const compressionMethod = compression_js_1.default.detect(this.compression, reqHeaders, resHeaders);
254
+ const compressionMethod = compression_1.default.detect(this.compression, reqHeaders, resHeaders);
255
255
  this.outputHeaders(statusCode, this.getClearedHeaders(resHeaders, compressionMethod));
256
256
  if (this.logRequest) {
257
257
  this.proxyRes
258
258
  .pipe(this.logRequest.responseBody)
259
- .pipe(compression_js_1.default.compress(compressionMethod))
259
+ .pipe(compression_1.default.compress(compressionMethod))
260
260
  .pipe(this.res);
261
261
  }
262
262
  else {
263
263
  this.proxyRes
264
- .pipe(compression_js_1.default.compress(compressionMethod))
264
+ .pipe(compression_1.default.compress(compressionMethod))
265
265
  .pipe(this.res);
266
266
  }
267
267
  this.httpLog.newResponse(this.req, statusCode, resHeaders, this.logRequest);
@@ -270,7 +270,7 @@ class TunnelHttp extends events_1.default {
270
270
  }
271
271
  createServe() {
272
272
  const reqHeaders = this.req.headers;
273
- const r = new serve_js_1.default(this.serve);
273
+ const r = new serve_1.default(this.serve);
274
274
  const method = this.getMethod();
275
275
  const path = this.getPath();
276
276
  this.logRequest = this.httpLog.newRequest(method, reqHeaders, path, utils_1.TUNNEL_IDENTIFIED_HTTP1, this.req);
@@ -280,17 +280,17 @@ class TunnelHttp extends events_1.default {
280
280
  this.res.end();
281
281
  }
282
282
  else {
283
- const compressionMethod = compression_js_1.default.detect(this.compression, reqHeaders, resHeaders);
283
+ const compressionMethod = compression_1.default.detect(this.compression, reqHeaders, resHeaders);
284
284
  this.outputHeaders(statusCode, this.getClearedHeaders(resHeaders, compressionMethod));
285
285
  if (this.logRequest) {
286
286
  stream
287
287
  .pipe(this.logRequest.responseBody)
288
- .pipe(compression_js_1.default.compress(compressionMethod))
288
+ .pipe(compression_1.default.compress(compressionMethod))
289
289
  .pipe(this.res);
290
290
  }
291
291
  else {
292
292
  stream
293
- .pipe(compression_js_1.default.compress(compressionMethod))
293
+ .pipe(compression_1.default.compress(compressionMethod))
294
294
  .pipe(this.res);
295
295
  }
296
296
  }
@@ -301,7 +301,7 @@ class TunnelHttp extends events_1.default {
301
301
  async createRequestHttps2() {
302
302
  const reqHeaders = this.req.headers;
303
303
  const authority = `${this.proto}://${(0, utils_1.getRealTargetHost)(this.host)}:${this.port}`;
304
- const client = await agent_js_1.default.getHttp2Client(authority, this.host, this.verify);
304
+ const client = await agent_1.default.getHttp2Client(authority, this.host, this.verify);
305
305
  const method = this.getMethod();
306
306
  const path = this.getPath();
307
307
  const headers = {
@@ -313,15 +313,15 @@ class TunnelHttp extends events_1.default {
313
313
  this.logRequest = this.httpLog.newRequest(method, headers, path, utils_1.TUNNEL_IDENTIFIED_HTTP2, this.req);
314
314
  r.on('response', (resHeaders) => {
315
315
  const status = resHeaders[':status'] || 200;
316
- const compressionMethod = compression_js_1.default.detect(this.compression, reqHeaders, resHeaders);
316
+ const compressionMethod = compression_1.default.detect(this.compression, reqHeaders, resHeaders);
317
317
  this.outputHeaders(status, this.getClearedHeaders(resHeaders, compressionMethod));
318
318
  if (this.logRequest) {
319
319
  r.pipe(this.logRequest.responseBody)
320
- .pipe(compression_js_1.default.compress(compressionMethod))
320
+ .pipe(compression_1.default.compress(compressionMethod))
321
321
  .pipe(this.res);
322
322
  }
323
323
  else {
324
- r.pipe(compression_js_1.default.compress(compressionMethod)).pipe(this.res);
324
+ r.pipe(compression_1.default.compress(compressionMethod)).pipe(this.res);
325
325
  }
326
326
  this.httpLog.newResponse(this.req, status, resHeaders, this.logRequest);
327
327
  });
@@ -407,8 +407,8 @@ class TunnelHttp extends events_1.default {
407
407
  this.proxyReq = this.createServe();
408
408
  }
409
409
  catch (err) {
410
- logger_js_1.default.debug(texts_js_1.LOG_ERROR);
411
- logger_js_1.default.debug(err);
410
+ logger_1.default.debug(texts_1.LOG_ERROR);
411
+ logger_1.default.debug(err);
412
412
  this.output504();
413
413
  return;
414
414
  }
@@ -427,8 +427,8 @@ class TunnelHttp extends events_1.default {
427
427
  this.proxyReq = await this.createRequest();
428
428
  }
429
429
  catch (err) {
430
- logger_js_1.default.debug(texts_js_1.LOG_ERROR);
431
- logger_js_1.default.debug(err);
430
+ logger_1.default.debug(texts_1.LOG_ERROR);
431
+ logger_1.default.debug(err);
432
432
  if (this.logRequest) {
433
433
  this.req.pipe(this.logRequest.requestBody);
434
434
  // no real request waiting for this data -> push it into the void
@@ -446,8 +446,8 @@ class TunnelHttp extends events_1.default {
446
446
  this.output504();
447
447
  });
448
448
  this.proxyReq.on('error', (err) => {
449
- logger_js_1.default.debug(texts_js_1.LOG_ERROR);
450
- logger_js_1.default.debug(err);
449
+ logger_1.default.debug(texts_1.LOG_ERROR);
450
+ logger_1.default.debug(err);
451
451
  this.output504();
452
452
  });
453
453
  this.proxyReq.on('close', () => {
@@ -6,18 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const events_1 = __importDefault(require("events"));
7
7
  const tls_1 = __importDefault(require("tls"));
8
8
  const net_1 = __importDefault(require("net"));
9
- const utils_js_1 = require("../utils.js");
10
9
  const utils_1 = require("../utils");
10
+ const utils_2 = require("../utils");
11
11
  const CHECK_INTERVAL = 300000;
12
12
  const CHECK_TIMEOUT = 5000;
13
13
  class TunnelIdentification extends events_1.default {
14
14
  constructor(proto, host, port, forceHttp2) {
15
15
  super();
16
16
  this.proto = proto;
17
- this.host = (0, utils_js_1.getRealTargetHost)(host);
17
+ this.host = (0, utils_1.getRealTargetHost)(host);
18
18
  this.port = port;
19
19
  this.forceHttp2 = forceHttp2;
20
- this.type = utils_1.TUNNEL_IDENTIFIED_HTTP1;
20
+ this.type = utils_2.TUNNEL_IDENTIFIED_HTTP1;
21
21
  this.identify();
22
22
  this.ts = setInterval(() => this.identify(), CHECK_INTERVAL);
23
23
  }
@@ -29,8 +29,8 @@ class TunnelIdentification extends events_1.default {
29
29
  }
30
30
  identify() {
31
31
  if (this.forceHttp2) {
32
- this.type = utils_1.TUNNEL_IDENTIFIED_HTTP2;
33
- this.emit(utils_1.EVENT_TUNNEL_IDENTIFIED, utils_1.TUNNEL_IDENTIFIED_HTTP2);
32
+ this.type = utils_2.TUNNEL_IDENTIFIED_HTTP2;
33
+ this.emit(utils_2.EVENT_TUNNEL_IDENTIFIED, utils_2.TUNNEL_IDENTIFIED_HTTP2);
34
34
  return;
35
35
  }
36
36
  let socket;
@@ -46,12 +46,12 @@ class TunnelIdentification extends events_1.default {
46
46
  const connected = () => {
47
47
  if (socket.alpnProtocol) {
48
48
  if (socket.alpnProtocol === 'h2') {
49
- this.type = utils_1.TUNNEL_IDENTIFIED_HTTP2;
50
- this.emit(utils_1.EVENT_TUNNEL_IDENTIFIED, utils_1.TUNNEL_IDENTIFIED_HTTP2);
49
+ this.type = utils_2.TUNNEL_IDENTIFIED_HTTP2;
50
+ this.emit(utils_2.EVENT_TUNNEL_IDENTIFIED, utils_2.TUNNEL_IDENTIFIED_HTTP2);
51
51
  }
52
52
  else {
53
- this.type = utils_1.TUNNEL_IDENTIFIED_HTTP1;
54
- this.emit(utils_1.EVENT_TUNNEL_IDENTIFIED, utils_1.TUNNEL_IDENTIFIED_HTTP1);
53
+ this.type = utils_2.TUNNEL_IDENTIFIED_HTTP1;
54
+ this.emit(utils_2.EVENT_TUNNEL_IDENTIFIED, utils_2.TUNNEL_IDENTIFIED_HTTP1);
55
55
  }
56
56
  close();
57
57
  }
@@ -59,12 +59,12 @@ class TunnelIdentification extends events_1.default {
59
59
  socket.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n');
60
60
  socket.on('data', (d) => {
61
61
  if (/HTTP\/1/.test(d.toString('utf8'))) {
62
- this.type = utils_1.TUNNEL_IDENTIFIED_HTTP1;
63
- this.emit(utils_1.EVENT_TUNNEL_IDENTIFIED, utils_1.TUNNEL_IDENTIFIED_HTTP1);
62
+ this.type = utils_2.TUNNEL_IDENTIFIED_HTTP1;
63
+ this.emit(utils_2.EVENT_TUNNEL_IDENTIFIED, utils_2.TUNNEL_IDENTIFIED_HTTP1);
64
64
  }
65
65
  else {
66
- this.type = utils_1.TUNNEL_IDENTIFIED_HTTP2;
67
- this.emit(utils_1.EVENT_TUNNEL_IDENTIFIED, utils_1.TUNNEL_IDENTIFIED_HTTP2);
66
+ this.type = utils_2.TUNNEL_IDENTIFIED_HTTP2;
67
+ this.emit(utils_2.EVENT_TUNNEL_IDENTIFIED, utils_2.TUNNEL_IDENTIFIED_HTTP2);
68
68
  }
69
69
  close();
70
70
  });
@@ -5,14 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const net_1 = require("net");
7
7
  const events_1 = __importDefault(require("events"));
8
- const utils_js_1 = require("../utils.js");
8
+ const utils_1 = require("../utils");
9
9
  class TunnelLatency extends events_1.default {
10
10
  constructor(host, port) {
11
11
  super();
12
12
  this.latency = -1;
13
13
  this.isChecking = false;
14
14
  this.port = port;
15
- this.host = (0, utils_js_1.getRealTargetHost)(host);
15
+ this.host = (0, utils_1.getRealTargetHost)(host);
16
16
  this.ts = null;
17
17
  }
18
18
  check() {
@@ -52,7 +52,7 @@ class TunnelLatency extends events_1.default {
52
52
  socket.on('ready', () => {
53
53
  const elapsed = process.hrtime(start);
54
54
  if (this.latency < 0)
55
- this.emit(utils_js_1.TUNNEL_LATENCY_EVENT_RECONNECTED);
55
+ this.emit(utils_1.TUNNEL_LATENCY_EVENT_RECONNECTED);
56
56
  this.latency = elapsed[0] * 1000 + elapsed[1] / 1000000; // ms
57
57
  clear();
58
58
  });