@serenity-js/rest
Version:
Serenity/JS Screenplay Pattern library for interacting with REST and other HTTP-based services, supporting comprehensive API testing and blended testing scenarios
52 lines • 2.03 kB
TypeScript
import type { AgentConnectOpts } from 'agent-base';
import { Agent } from 'agent-base';
import * as http from 'http';
import { type HttpProxyAgentOptions } from 'http-proxy-agent';
import { type HttpsProxyAgentOptions } from 'https-proxy-agent';
type GetProxyForUrlCallback = (url: string) => string;
export type ProxyAgentOptions = HttpProxyAgentOptions<''> & HttpsProxyAgentOptions<''> & {
/**
* Default `http.Agent` instance to use when no proxy is
* configured for a request. Defaults to a new `http.Agent()`
* instance with the proxy agent options passed in.
*/
httpAgent?: http.Agent;
/**
* Default `http.Agent` instance to use when no proxy is
* configured for a request. Defaults to a new `https.Agent()`
* instance with the proxy agent options passed in.
*/
httpsAgent?: http.Agent;
/**
* A callback to dynamically determine the proxy to use for the given URL.
*/
getProxyForUrl?: GetProxyForUrlCallback;
};
/**
* A simplified version of the original
* [`ProxyAgent`](https://github.com/TooTallNate/proxy-agents/blob/5923589c2e5206504772c250ac4f20fc31122d3b/packages/proxy-agent/src/index.ts)
* with fewer dependencies.
*
* Delegates requests to the appropriate `Agent` subclass based on the "proxy"
* environment variables, or the provided `agentOptions.getProxyForUrl` callback.
*
* Uses an LRU cache to prevent unnecessary creation of proxy `http.Agent` instances.
*/
export declare class ProxyAgent extends Agent {
private readonly agentOptions;
private static proxyAgents;
/**
* Cache for `Agent` instances.
*/
private readonly cache;
private readonly httpAgent;
private readonly httpsAgent;
private readonly getProxyForUrl;
constructor(agentOptions: ProxyAgentOptions);
connect(request: http.ClientRequest, options: AgentConnectOpts): Promise<http.Agent>;
private createAgent;
private isValidProtocol;
destroy(): void;
}
export {};
//# sourceMappingURL=ProxyAgent.d.ts.map