Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Apr 28, 2023
1 parent 8f60cdb commit 3a829c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
21 changes: 16 additions & 5 deletions packages/http-proxy-agent/src/index.ts
Expand Up @@ -7,6 +7,20 @@ import { Agent, AgentConnectOpts } from 'agent-base';

const debug = createDebug('http-proxy-agent');

// eslint-disable-next-line @typescript-eslint/no-unused-vars
type Protocol<T> = T extends `${infer Protocol}:${infer _}` ? Protocol : never;

type ConnectOptsMap = {
http: Omit<net.TcpNetConnectOpts, 'host' | 'port'>;
https: Omit<tls.ConnectionOptions, 'host' | 'port'>;
}

export type HttpProxyAgentOptions<T> = {
[P in keyof ConnectOptsMap]: Protocol<T> extends P
? ConnectOptsMap[P]
: never;
}[keyof ConnectOptsMap];

interface HttpProxyAgentClientRequest extends http.ClientRequest {
outputData?: {
data: string;
Expand All @@ -23,18 +37,15 @@ function isHTTPS(protocol?: string | null): boolean {
* The `HttpProxyAgent` implements an HTTP Agent subclass that connects
* to the specified "HTTP proxy server" in order to proxy HTTP requests.
*/
export class HttpProxyAgent extends Agent {
export class HttpProxyAgent<Uri extends string> extends Agent {
readonly proxy: URL;
connectOpts: net.TcpNetConnectOpts & tls.ConnectionOptions;

get secureProxy() {
return isHTTPS(this.proxy.protocol);
}

constructor(
proxy: string | URL,
opts?: net.TcpNetConnectOpts & tls.ConnectionOptions
) {
constructor(proxy: Uri | URL, opts?: HttpProxyAgentOptions<Uri>) {
super();
this.proxy = typeof proxy === 'string' ? new URL(proxy) : proxy;
debug('Creating new HttpProxyAgent instance: %o', this.proxy);
Expand Down
8 changes: 4 additions & 4 deletions packages/socks-proxy-agent/src/index.ts
Expand Up @@ -88,17 +88,17 @@ export class SocksProxyAgent extends Agent {
private readonly tlsConnectionOptions: tls.ConnectionOptions;
public timeout: number | null;

constructor(input: string | URL, options?: SocksProxyAgentOptionsExtra) {
constructor(uri: string | URL, opts?: SocksProxyAgentOptionsExtra) {
super();

const url = typeof input === 'string' ? new URL(input) : input;
const url = typeof uri === 'string' ? new URL(uri) : uri;
const { proxy, lookup } = parseSocksURL(url);

this.shouldLookup = lookup;
this.proxy = proxy;
//this.tlsConnectionOptions = proxyOptions.tls != null ? proxyOptions.tls : {}
this.tlsConnectionOptions = {};
this.timeout = options?.timeout ?? null;
this.timeout = opts?.timeout ?? null;
}

/**
Expand All @@ -114,7 +114,7 @@ export class SocksProxyAgent extends Agent {
let { host } = opts;
const { port, lookup: lookupFn = dns.lookup } = opts;

if (host == null) {
if (!host) {
throw new Error('No `host` defined!');
}

Expand Down

0 comments on commit 3a829c6

Please sign in to comment.