@jonathanleelx/meddle 0.4.5-beta.6 → 0.4.5

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.
@@ -0,0 +1,25 @@
1
+ import type { Socket } from 'net';
2
+ import { isExpectedSocketError } from './connect-tunnel';
3
+ export { isExpectedSocketError };
4
+ export interface MitmClientSocketOptions {
5
+ /** Called once when the socket is accepted (tracking). */
6
+ onTrack: () => void;
7
+ /** Called once when the socket closes (untracking). */
8
+ onUntrack: () => void;
9
+ /** Attach per-connection metadata (e.g. client identity registry). */
10
+ attachIdentity: (socket: Socket) => void;
11
+ /** Report non-routine errors (ECONNRESET/EPIPE are swallowed). */
12
+ onUnexpectedError?: (err: NodeJS.ErrnoException) => void;
13
+ }
14
+ /**
15
+ * Wire the per-connection MITM TLS socket.
16
+ *
17
+ * A client resetting its TLS connection (ECONNRESET) can surface as an
18
+ * 'error' on the socket. Without a persistent listener the error propagates
19
+ * to uncaughtException and kills the whole proxy (observed in the deno
20
+ * binary). The listener is `on` (not `once`) because a socket can emit
21
+ * 'error' more than once; `once` would be consumed by the first error and a
22
+ * second emission would have no listener.
23
+ */
24
+ export declare function wireMitmClientSocket(tlsSocket: Socket, options: MitmClientSocketOptions): void;
25
+ //# sourceMappingURL=mitm-socket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mitm-socket.d.ts","sourceRoot":"","sources":["../../core/mitm-socket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAExD,OAAO,EAAE,qBAAqB,EAAE,CAAA;AAEhC,MAAM,WAAW,uBAAuB;IACpC,0DAA0D;IAC1D,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,uDAAuD;IACvD,SAAS,EAAE,MAAM,IAAI,CAAA;IACrB,sEAAsE;IACtE,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IACxC,kEAAkE;IAClE,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,cAAc,KAAK,IAAI,CAAA;CAC3D;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAO9F"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isExpectedSocketError = void 0;
4
+ exports.wireMitmClientSocket = wireMitmClientSocket;
5
+ const connect_tunnel_1 = require("./connect-tunnel");
6
+ Object.defineProperty(exports, "isExpectedSocketError", { enumerable: true, get: function () { return connect_tunnel_1.isExpectedSocketError; } });
7
+ /**
8
+ * Wire the per-connection MITM TLS socket.
9
+ *
10
+ * A client resetting its TLS connection (ECONNRESET) can surface as an
11
+ * 'error' on the socket. Without a persistent listener the error propagates
12
+ * to uncaughtException and kills the whole proxy (observed in the deno
13
+ * binary). The listener is `on` (not `once`) because a socket can emit
14
+ * 'error' more than once; `once` would be consumed by the first error and a
15
+ * second emission would have no listener.
16
+ */
17
+ function wireMitmClientSocket(tlsSocket, options) {
18
+ options.onTrack();
19
+ tlsSocket.once('close', () => { options.onUntrack(); });
20
+ options.attachIdentity(tlsSocket);
21
+ tlsSocket.on('error', (err) => {
22
+ if (!(0, connect_tunnel_1.isExpectedSocketError)(err))
23
+ options.onUnexpectedError?.(err);
24
+ });
25
+ }
26
+ //# sourceMappingURL=mitm-socket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mitm-socket.js","sourceRoot":"","sources":["../../core/mitm-socket.ts"],"names":[],"mappings":";;;AA0BA,oDAOC;AAhCD,qDAAwD;AAE/C,sGAFA,sCAAqB,OAEA;AAa9B;;;;;;;;;GASG;AACH,SAAgB,oBAAoB,CAAC,SAAiB,EAAE,OAAgC;IACpF,OAAO,CAAC,OAAO,EAAE,CAAA;IACjB,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,SAAS,EAAE,CAAA,CAAC,CAAC,CAAC,CAAA;IACtD,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,CAAA;IACjC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAA0B,EAAE,EAAE;QACjD,IAAI,CAAC,IAAA,sCAAqB,EAAC,GAAG,CAAC;YAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC,GAAG,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;AACN,CAAC"}
package/index.js CHANGED
@@ -13,6 +13,7 @@ const {
13
13
  establishConnectTunnel,
14
14
  isExpectedSocketError,
15
15
  } = require('./dist/core/connect-tunnel')
16
+ const { wireMitmClientSocket } = require('./dist/core/mitm-socket')
16
17
  const {
17
18
  createClientIdentityResolver,
18
19
  createMitmClientIdentityRegistry,
@@ -776,13 +777,18 @@ proxyServer.on('connect', async (req, socket, head) => {
776
777
  clientIdentityRegistry.register(remotePort, identity)
777
778
  }
778
779
  server.on('secureConnection', tlsSocket => {
779
- markMitmServerUsed(server)
780
- server._epActiveSockets.add(tlsSocket)
781
- tlsSocket.once('close', () => {
782
- server._epActiveSockets.delete(tlsSocket)
783
- markMitmServerUsed(server)
780
+ wireMitmClientSocket(tlsSocket, {
781
+ onTrack: () => {
782
+ markMitmServerUsed(server)
783
+ server._epActiveSockets.add(tlsSocket)
784
+ },
785
+ onUntrack: () => {
786
+ server._epActiveSockets.delete(tlsSocket)
787
+ markMitmServerUsed(server)
788
+ },
789
+ attachIdentity: socket => clientIdentityRegistry.attach(socket),
790
+ onUnexpectedError: err => proxyDebug('MITM client socket error', originHost, getErrorMessage(err)),
784
791
  })
785
- clientIdentityRegistry.attach(tlsSocket)
786
792
  })
787
793
 
788
794
  // WebSocket 代理(MITM HTTPS 服务器)- 使用 noServer 模式,统一在此处理并强制上游→客户端为文本
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jonathanleelx/meddle",
3
- "version": "0.4.5-beta.6",
3
+ "version": "0.4.5",
4
4
  "description": "A simple development proxy server with custom routing rules, mock responses, HTTPS interception, and a plugin system",
5
5
  "type": "commonjs",
6
6
  "main": "index.js",