@dev-swarup/http-mitm-proxy 0.9.6 → 0.9.7

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 (2) hide show
  1. package/lib/proxy.js +41 -4
  2. package/package.json +1 -1
package/lib/proxy.js CHANGED
@@ -37,6 +37,7 @@ var Proxy = function () {
37
37
  this.onResponseHeadersHandlers = [];
38
38
  this.onResponseDataHandlers = [];
39
39
  this.onResponseEndHandlers = [];
40
+ this.socketMapping = new Map();
40
41
  this.responseContentPotentiallyModified = false;
41
42
  };
42
43
 
@@ -424,16 +425,44 @@ Proxy.prototype._onHttpServerConnectData = function (req, socket, head) {
424
425
  port: port,
425
426
  },
426
427
  function () {
428
+ if (conn.localPort) {
429
+ self.socketMapping.set(conn.localPort, socket);
430
+ }
431
+
427
432
  // create a tunnel between the two hosts
428
433
  conn.write(head);
429
434
  conn.pipe(socket);
430
435
  return socket.pipe(conn);
431
436
  }
432
437
  );
433
- conn.on('error', self._onSocketError.bind(self, 'PROXY_TO_PROXY_SOCKET'));
434
- conn.once('end', () => connClosing(socket));
435
- conn.once('finish', () => connClosing(socket));
436
- conn.once('close', () => connClosing(socket));
438
+ conn.on('error', ()=> {
439
+ if (conn.localPort) {
440
+ self.socketMapping.delete(conn.localPort);
441
+ };
442
+
443
+ self._onSocketError.bind(self, 'PROXY_TO_PROXY_SOCKET');
444
+ });
445
+ conn.once('end', () => {
446
+ if (conn.localPort) {
447
+ self.socketMapping.delete(conn.localPort);
448
+ };
449
+
450
+ connClosing(socket);
451
+ });
452
+ conn.once('finish', () => {
453
+ if (conn.localPort) {
454
+ self.socketMapping.delete(conn.localPort);
455
+ };
456
+
457
+ connClosing(socket);
458
+ });
459
+ conn.once('close', () => {
460
+ if (conn.localPort) {
461
+ self.socketMapping.delete(conn.localPort);
462
+ };
463
+
464
+ connClosing(socket);
465
+ });
437
466
  conn.setNoDelay();
438
467
  socket.once('end', () => socketClosing(conn));
439
468
  socket.once('finish', () => socketClosing(conn));
@@ -664,6 +693,14 @@ Proxy.prototype._onWebSocketServerConnect = function (isSSL, ws, upgradeReq) {
664
693
 
665
694
  Proxy.prototype._onHttpServerRequest = function (isSSL, clientToProxyRequest, proxyToClientResponse) {
666
695
  var self = this;
696
+
697
+ const remotePort = clientToProxyRequest.socket.remotePort;
698
+ if (remotePort && self.socketMapping.has(remotePort)) {
699
+ clientToProxyRequest.originalSocket = self.socketMapping.get(remotePort);
700
+ }
701
+
702
+ self.socketMapping.delete(remotePort);
703
+
667
704
  var ctx = {
668
705
  isSSL: isSSL,
669
706
  clientToProxyRequest: clientToProxyRequest,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-swarup/http-mitm-proxy",
3
- "version": "0.9.6",
3
+ "version": "0.9.7",
4
4
  "description": "HTTP Man In The Middle (MITM) Proxy. This is a fork of Joe Ferners' library node-http-mitm-proxy. Its first release was identical to the master version of the original library, commit 66ac0f5d3298f66b731f90ebf1e9b430fa5d76eb. I decided to publish a scoped version of this library to npm, since I needed the codebase in npm. It is only intended for my own library cypress-ntlm-auth. Use at you own risk!",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",