-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.d.ts
141 lines (109 loc) · 4.27 KB
/
index.d.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// See https://github.com/facebook/jest/issues/2549
// eslint-disable-next-line node/prefer-global/url
import {URL} from 'url';
import {EventEmitter} from 'events';
import tls = require('tls');
import http = require('http');
import https = require('https');
import http2 = require('http2');
// Note: do not convert this to import from.
import QuickLRU = require('quick-lru');
export interface RequestOptions extends Omit<https.RequestOptions, 'session' | 'agent'> {
tlsSession?: tls.ConnectionOptions['session'];
h2session?: http2.ClientHttp2Session;
agent?: Agent | false;
// Required because @types/node is missing types
ALPNProtocols?: string[];
}
export interface AutoRequestOptions extends Omit<RequestOptions, 'agent' | 'h2session'> {
agent?: {
http?: http.Agent | false;
https?: https.Agent | false;
http2?: Agent | false;
};
resolveProtocol?: ResolveProtocolFunction;
}
export interface EntryFunction {
(): Promise<void>;
completed: boolean;
destroyed: boolean;
listeners: PromiseListeners;
}
export interface AgentOptions {
timeout?: number;
maxSessions?: number;
maxEmptySessions?: number;
maxCachedTlsSessions?: number;
}
export interface PromiseListeners {
resolve: (value: unknown) => void;
reject: (error: Error) => void;
}
export class Agent extends EventEmitter {
sessions: Record<string, http2.ClientHttp2Session[]>;
queue: Record<string, Record<string, EntryFunction>>;
timeout: number;
maxSessions: number;
maxEmptySessions: number;
protocol: string;
settings: http2.Settings;
tlsSessionCache: QuickLRU<string, string>;
emptySessionCount: number;
pendingSessionCount: number;
sessionCount: number;
constructor(options?: AgentOptions);
static connect(origin: URL, options: http2.SecureClientSessionOptions): tls.TLSSocket;
normalizeOptions(options: http2.ClientSessionRequestOptions): string;
getSession(origin: string | URL, options?: http2.SecureClientSessionOptions, listeners?: PromiseListeners): Promise<http2.ClientHttp2Session>;
request(origin: string | URL, options?: http2.SecureClientSessionOptions, headers?: http2.OutgoingHttpHeaders, streamOptions?: http2.ClientSessionRequestOptions): Promise<http2.ClientHttp2Stream>;
createConnection(origin: URL, options: http2.SecureClientSessionOptions): Promise<tls.TLSSocket>;
closeEmptySessions(count?: number): void;
destroy(reason?: Error): void;
}
export interface ProxyOptions {
headers?: http2.OutgoingHttpHeaders;
raw?: boolean;
url: URL | string;
}
export namespace proxies {
class HttpOverHttp2 extends http.Agent {
constructor(options: http.AgentOptions & {proxyOptions: ProxyOptions});
}
class HttpsOverHttp2 extends https.Agent {
constructor(options: https.AgentOptions & {proxyOptions: ProxyOptions});
}
class Http2OverHttp2 extends Agent {
constructor(options: AgentOptions & {proxyOptions: ProxyOptions});
}
class Http2OverHttp extends Agent {
constructor(options: AgentOptions & {proxyOptions: ProxyOptions});
}
class Http2OverHttps extends Agent {
constructor(options: AgentOptions & {proxyOptions: ProxyOptions});
}
}
export type RequestFunction<T, O = RequestOptions> =
((url: string | URL, options?: O, callback?: (response: http.IncomingMessage) => void) => T) &
((url: string | URL, callback?: (response: http.IncomingMessage) => void) => T) &
((options: O, callback?: (response: http.IncomingMessage) => void) => T);
export const globalAgent: Agent;
export type ResolveProtocolResult = {
alpnProtocol: string;
socket?: tls.TLSSocket;
timeout?: boolean;
};
export type ResolveProtocolFunction = (options: AutoRequestOptions) => Promise<ResolveProtocolResult>;
type Promisable<T> = T | Promise<T>;
export type ResolveProtocolConnectFunction = (options: tls.ConnectionOptions, callback: () => void) => Promisable<tls.TLSSocket>;
export const request: RequestFunction<http.ClientRequest>;
export const get: RequestFunction<http.ClientRequest>;
export const auto: RequestFunction<Promise<http.ClientRequest>, AutoRequestOptions> & {
protocolCache: QuickLRU<string, string>;
resolveProtocol: ResolveProtocolFunction;
createResolveProtocol: (cache: Map<string, string>, queue: Map<string, Promise<ResolveProtocolResult>>, connect?: ResolveProtocolConnectFunction) => ResolveProtocolFunction;
};
export {
ClientRequest,
IncomingMessage
} from 'http';
export * from 'http2';