Skip to content

Add a lookup option to allow users to implement their own DNS resolution #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ __Arguments__
* forceSNI - force use of [SNI](https://en.wikipedia.org/wiki/Server_Name_Indication) by the client. Allow node-http-mitm-proxy to handle all HTTPS requests with a single internal server.
* httpsPort - The port or named socket for https server to listen on. _(forceSNI must be enabled)_
* forceChunkedRequest - Setting this option will remove the content-length from the proxy to server request, forcing chunked encoding.
* lookup - The DNS lookup function to use. This option can be used to avoid the default synchronous DNS resolution. See [#314](https://github.com/joeferner/node-http-mitm-proxy/issues/314) for details.

__Example__

Expand Down
1 change: 1 addition & 0 deletions lib/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,7 @@ export class Proxy implements IProxy {
port: hostPort.port,
headers,
agent: ctx.isSSL ? self.httpsAgent : self.httpAgent,
lookup: this.options.lookup,
};
return self._onRequest(ctx, (err) => {
if (err) {
Expand Down
4 changes: 4 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type CA from "../lib/ca";
import type WebSocket from "ws";
import type { Server } from "https";
import type { WebSocket as WebSocketType, WebSocketServer } from "ws";
import type { LookupFunction } from 'net';

export interface IProxyStatic {
(): IProxy;
Expand Down Expand Up @@ -34,6 +35,8 @@ export interface IProxyOptions {
httpsPort?: number;
/** - Setting this option will remove the content-length from the proxy to server request, forcing chunked encoding */
forceChunkedRequest?: boolean;
/** - The DNS lookup function to use. This option can be used to avoid the default synchronous DNS resolution. See #314 for details. */
lookup?: LookupFunction;
}

export interface IProxySSLServer {
Expand Down Expand Up @@ -306,6 +309,7 @@ export type IContext = ICallbacks &
port: string | number | null | undefined;
headers: { [key: string]: string };
agent: http.Agent;
lookup: LookupFunction | undefined;
};

onRequestHandlers: OnRequestParams[];
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.