/
HttpProxyAgent.ts
45 lines (40 loc) · 1.11 KB
/
HttpProxyAgent.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import net from 'net';
import type {
AgentType,
ConnectionCallbackType,
ConnectionConfigurationType,
GetUrlProxyMethodType,
IsProxyConfiguredMethodType,
MustUrlUseProxyMethodType,
} from '../types';
import Agent from './Agent';
class HttpProxyAgent extends Agent {
// @see https://github.com/sindresorhus/eslint-plugin-unicorn/issues/169#issuecomment-486980290
public constructor (
isProxyConfigured: IsProxyConfiguredMethodType,
mustUrlUseProxy: MustUrlUseProxyMethodType,
getUrlProxy: GetUrlProxyMethodType,
fallbackAgent: AgentType,
socketConnectionTimeout: number,
ca: string[] | string | undefined,
) {
super(
isProxyConfigured,
mustUrlUseProxy,
getUrlProxy,
fallbackAgent,
socketConnectionTimeout,
ca,
);
this.protocol = 'http:';
this.defaultPort = 80;
}
public createConnection (configuration: ConnectionConfigurationType, callback: ConnectionCallbackType) {
const socket = net.connect(
configuration.proxy.port,
configuration.proxy.hostname,
);
callback(null, socket);
}
}
export default HttpProxyAgent;