forked from moll/node-mitm
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
2,167 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Based on code by @alejo90 | ||
* @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/1d58999ab82c14bed518d0aec2ab2a5343e9f83b/types/mitm/index.d.ts | ||
* @license MIT | ||
*/ | ||
|
||
import * as http from "http"; | ||
import * as net from "net"; | ||
|
||
interface SocketOptions { | ||
port: number; | ||
host?: string | undefined; | ||
localAddress?: string | undefined; | ||
localPort?: string | undefined; | ||
family?: number | undefined; | ||
allowHalfOpen?: boolean | undefined; | ||
} | ||
|
||
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 default 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as net from "net"; | ||
import * as http from "http"; | ||
|
||
import { expectType } from "tsd"; | ||
|
||
import Mitm from "./index.js"; | ||
|
||
export function test(mitm: Mitm) { | ||
mitm.disable(); | ||
|
||
mitm.on("connect", (bypassableSocket, opts): void => { | ||
expectType<() => void>(bypassableSocket.bypass); | ||
|
||
expectType<number>(opts.port); | ||
expectType<string | undefined>(opts.host); | ||
}); | ||
|
||
mitm.on("connection", (socket, opts): void => { | ||
expectType<net.Socket>(socket); | ||
|
||
expectType<number>(opts.port); | ||
expectType<string | undefined>(opts.host); | ||
}); | ||
|
||
mitm.on("request", (request, response): void => { | ||
expectType<http.IncomingMessage>(request); | ||
expectType<http.ServerResponse>(response); | ||
}); | ||
} |
Oops, something went wrong.