diff --git a/mitm/mitm-tests.ts b/mitm/mitm-tests.ts new file mode 100644 index 0000000000..90570ef377 --- /dev/null +++ b/mitm/mitm-tests.ts @@ -0,0 +1,18 @@ +/// + +import Mitm, {BypassableSocket, SocketOptions} from 'mitm'; +import {Socket} from 'net'; +import {IncomingMessage, ServerResponse} from 'http'; + +const mitm = Mitm(); +mitm.disable(); + +mitm.on('connect', (socket: BypassableSocket, opts: SocketOptions): void => { + socket.bypass(); +}); + +mitm.on('connection', (socket: Socket, opts: SocketOptions): void => { +}); + +mitm.on('request', (request: IncomingMessage, response: ServerResponse): void => { +}); diff --git a/mitm/mitm.d.ts b/mitm/mitm.d.ts new file mode 100644 index 0000000000..b9cabb633c --- /dev/null +++ b/mitm/mitm.d.ts @@ -0,0 +1,44 @@ +// Type definitions for mitm v1.3.0 +// Project: https://github.com/moll/node-mitm +// Definitions by: Alejandro Sánchez +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module 'mitm' { + import * as http from 'http'; + import * as net from 'net'; + + export interface SocketOptions { + port: number; + host?: string; + localAddress?: string; + localPort?: string; + family?: number; + allowHalfOpen?: boolean; + } + + export interface BypassableSocket extends net.Socket { + bypass(): void + } + + type SocketConnectCallback = (socket: BypassableSocket, opts: SocketOptions) => void; + + type SocketConnectionCallback = (socket: net.Socket, opts: SocketOptions) => void; + + type HttpCallback = (request: http.IncomingMessage, response: http.ServerResponse) => void; + + type Event = 'connect' | 'connection' | 'request'; + + type Callback = SocketConnectCallback | SocketConnectionCallback | HttpCallback; + + export interface Mitm { + disable(): void; + on(event: Event, callback: Callback): void; + on(event: 'connect', callback: SocketConnectCallback): void; + on(event: 'connection', callback: SocketConnectionCallback): void; + on(event: 'request', callback: HttpCallback): void; + } + + export default function (): Mitm; +}