[6a3a178] | 1 | declare module 'http' {
|
---|
| 2 | import * as stream from 'stream';
|
---|
| 3 | import { URL } from 'url';
|
---|
| 4 | import { Socket, Server as NetServer } from 'net';
|
---|
| 5 |
|
---|
| 6 | // incoming headers will never contain number
|
---|
| 7 | interface IncomingHttpHeaders {
|
---|
| 8 | 'accept'?: string | undefined;
|
---|
| 9 | 'accept-language'?: string | undefined;
|
---|
| 10 | 'accept-patch'?: string | undefined;
|
---|
| 11 | 'accept-ranges'?: string | undefined;
|
---|
| 12 | 'access-control-allow-credentials'?: string | undefined;
|
---|
| 13 | 'access-control-allow-headers'?: string | undefined;
|
---|
| 14 | 'access-control-allow-methods'?: string | undefined;
|
---|
| 15 | 'access-control-allow-origin'?: string | undefined;
|
---|
| 16 | 'access-control-expose-headers'?: string | undefined;
|
---|
| 17 | 'access-control-max-age'?: string | undefined;
|
---|
| 18 | 'access-control-request-headers'?: string | undefined;
|
---|
| 19 | 'access-control-request-method'?: string | undefined;
|
---|
| 20 | 'age'?: string | undefined;
|
---|
| 21 | 'allow'?: string | undefined;
|
---|
| 22 | 'alt-svc'?: string | undefined;
|
---|
| 23 | 'authorization'?: string | undefined;
|
---|
| 24 | 'cache-control'?: string | undefined;
|
---|
| 25 | 'connection'?: string | undefined;
|
---|
| 26 | 'content-disposition'?: string | undefined;
|
---|
| 27 | 'content-encoding'?: string | undefined;
|
---|
| 28 | 'content-language'?: string | undefined;
|
---|
| 29 | 'content-length'?: string | undefined;
|
---|
| 30 | 'content-location'?: string | undefined;
|
---|
| 31 | 'content-range'?: string | undefined;
|
---|
| 32 | 'content-type'?: string | undefined;
|
---|
| 33 | 'cookie'?: string | undefined;
|
---|
| 34 | 'date'?: string | undefined;
|
---|
| 35 | 'etag'?: string | undefined;
|
---|
| 36 | 'expect'?: string | undefined;
|
---|
| 37 | 'expires'?: string | undefined;
|
---|
| 38 | 'forwarded'?: string | undefined;
|
---|
| 39 | 'from'?: string | undefined;
|
---|
| 40 | 'host'?: string | undefined;
|
---|
| 41 | 'if-match'?: string | undefined;
|
---|
| 42 | 'if-modified-since'?: string | undefined;
|
---|
| 43 | 'if-none-match'?: string | undefined;
|
---|
| 44 | 'if-unmodified-since'?: string | undefined;
|
---|
| 45 | 'last-modified'?: string | undefined;
|
---|
| 46 | 'location'?: string | undefined;
|
---|
| 47 | 'origin'?: string | undefined;
|
---|
| 48 | 'pragma'?: string | undefined;
|
---|
| 49 | 'proxy-authenticate'?: string | undefined;
|
---|
| 50 | 'proxy-authorization'?: string | undefined;
|
---|
| 51 | 'public-key-pins'?: string | undefined;
|
---|
| 52 | 'range'?: string | undefined;
|
---|
| 53 | 'referer'?: string | undefined;
|
---|
| 54 | 'retry-after'?: string | undefined;
|
---|
| 55 | 'set-cookie'?: string[] | undefined;
|
---|
| 56 | 'strict-transport-security'?: string | undefined;
|
---|
| 57 | 'tk'?: string | undefined;
|
---|
| 58 | 'trailer'?: string | undefined;
|
---|
| 59 | 'transfer-encoding'?: string | undefined;
|
---|
| 60 | 'upgrade'?: string | undefined;
|
---|
| 61 | 'user-agent'?: string | undefined;
|
---|
| 62 | 'vary'?: string | undefined;
|
---|
| 63 | 'via'?: string | undefined;
|
---|
| 64 | 'warning'?: string | undefined;
|
---|
| 65 | 'www-authenticate'?: string | undefined;
|
---|
| 66 | [header: string]: string | string[] | undefined;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | // outgoing headers allows numbers (as they are converted internally to strings)
|
---|
| 70 | interface OutgoingHttpHeaders {
|
---|
| 71 | [header: string]: number | string | string[] | undefined;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | interface ClientRequestArgs {
|
---|
| 75 | protocol?: string | null | undefined;
|
---|
| 76 | host?: string | null | undefined;
|
---|
| 77 | hostname?: string | null | undefined;
|
---|
| 78 | family?: number | undefined;
|
---|
| 79 | port?: number | string | null | undefined;
|
---|
| 80 | defaultPort?: number | string | undefined;
|
---|
| 81 | localAddress?: string | undefined;
|
---|
| 82 | socketPath?: string | undefined;
|
---|
| 83 | method?: string | undefined;
|
---|
| 84 | path?: string | null | undefined;
|
---|
| 85 | headers?: OutgoingHttpHeaders | undefined;
|
---|
| 86 | auth?: string | null | undefined;
|
---|
| 87 | agent?: Agent | boolean | undefined;
|
---|
| 88 | _defaultAgent?: Agent | undefined;
|
---|
| 89 | timeout?: number | undefined;
|
---|
| 90 | setHost?: boolean | undefined;
|
---|
| 91 | // https://github.com/nodejs/node/blob/master/lib/_http_client.js#L278
|
---|
| 92 | createConnection?: ((options: ClientRequestArgs, oncreate: (err: Error, socket: Socket) => void) => Socket) | undefined;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | interface ServerOptions {
|
---|
| 96 | IncomingMessage?: typeof IncomingMessage | undefined;
|
---|
| 97 | ServerResponse?: typeof ServerResponse | undefined;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | type RequestListener = (req: IncomingMessage, res: ServerResponse) => void;
|
---|
| 101 |
|
---|
| 102 | class Server extends NetServer {
|
---|
| 103 | constructor(requestListener?: RequestListener);
|
---|
| 104 | constructor(options: ServerOptions, requestListener?: RequestListener);
|
---|
| 105 |
|
---|
| 106 | setTimeout(msecs?: number, callback?: () => void): this;
|
---|
| 107 | setTimeout(callback: () => void): this;
|
---|
| 108 | /**
|
---|
| 109 | * Limits maximum incoming headers count. If set to 0, no limit will be applied.
|
---|
| 110 | * @default 2000
|
---|
| 111 | * {@link https://nodejs.org/api/http.html#http_server_maxheaderscount}
|
---|
| 112 | */
|
---|
| 113 | maxHeadersCount: number | null;
|
---|
| 114 | timeout: number;
|
---|
| 115 | /**
|
---|
| 116 | * Limit the amount of time the parser will wait to receive the complete HTTP headers.
|
---|
| 117 | * @default 40000
|
---|
| 118 | * {@link https://nodejs.org/api/http.html#http_server_headerstimeout}
|
---|
| 119 | */
|
---|
| 120 | headersTimeout: number;
|
---|
| 121 | keepAliveTimeout: number;
|
---|
| 122 | addListener(event: string, listener: (...args: any[]) => void): this;
|
---|
| 123 | addListener(event: 'close', listener: () => void): this;
|
---|
| 124 | addListener(event: 'connection', listener: (socket: Socket) => void): this;
|
---|
| 125 | addListener(event: 'error', listener: (err: Error) => void): this;
|
---|
| 126 | addListener(event: 'listening', listener: () => void): this;
|
---|
| 127 | addListener(event: 'checkContinue', listener: RequestListener): this;
|
---|
| 128 | addListener(event: 'checkExpectation', listener: RequestListener): this;
|
---|
| 129 | addListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
|
---|
| 130 | addListener(event: 'connect', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
|
---|
| 131 | addListener(event: 'request', listener: RequestListener): this;
|
---|
| 132 | addListener(event: 'upgrade', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
|
---|
| 133 | emit(event: string, ...args: any[]): boolean;
|
---|
| 134 | emit(event: 'close'): boolean;
|
---|
| 135 | emit(event: 'connection', socket: Socket): boolean;
|
---|
| 136 | emit(event: 'error', err: Error): boolean;
|
---|
| 137 | emit(event: 'listening'): boolean;
|
---|
| 138 | emit(event: 'checkContinue', req: IncomingMessage, res: ServerResponse): boolean;
|
---|
| 139 | emit(event: 'checkExpectation', req: IncomingMessage, res: ServerResponse): boolean;
|
---|
| 140 | emit(event: 'clientError', err: Error, socket: stream.Duplex): boolean;
|
---|
| 141 | emit(event: 'connect', req: IncomingMessage, socket: stream.Duplex, head: Buffer): boolean;
|
---|
| 142 | emit(event: 'request', req: IncomingMessage, res: ServerResponse): boolean;
|
---|
| 143 | emit(event: 'upgrade', req: IncomingMessage, socket: stream.Duplex, head: Buffer): boolean;
|
---|
| 144 | on(event: string, listener: (...args: any[]) => void): this;
|
---|
| 145 | on(event: 'close', listener: () => void): this;
|
---|
| 146 | on(event: 'connection', listener: (socket: Socket) => void): this;
|
---|
| 147 | on(event: 'error', listener: (err: Error) => void): this;
|
---|
| 148 | on(event: 'listening', listener: () => void): this;
|
---|
| 149 | on(event: 'checkContinue', listener: RequestListener): this;
|
---|
| 150 | on(event: 'checkExpectation', listener: RequestListener): this;
|
---|
| 151 | on(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
|
---|
| 152 | on(event: 'connect', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
|
---|
| 153 | on(event: 'request', listener: RequestListener): this;
|
---|
| 154 | on(event: 'upgrade', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
|
---|
| 155 | once(event: string, listener: (...args: any[]) => void): this;
|
---|
| 156 | once(event: 'close', listener: () => void): this;
|
---|
| 157 | once(event: 'connection', listener: (socket: Socket) => void): this;
|
---|
| 158 | once(event: 'error', listener: (err: Error) => void): this;
|
---|
| 159 | once(event: 'listening', listener: () => void): this;
|
---|
| 160 | once(event: 'checkContinue', listener: RequestListener): this;
|
---|
| 161 | once(event: 'checkExpectation', listener: RequestListener): this;
|
---|
| 162 | once(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
|
---|
| 163 | once(event: 'connect', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
|
---|
| 164 | once(event: 'request', listener: RequestListener): this;
|
---|
| 165 | once(event: 'upgrade', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
|
---|
| 166 | prependListener(event: string, listener: (...args: any[]) => void): this;
|
---|
| 167 | prependListener(event: 'close', listener: () => void): this;
|
---|
| 168 | prependListener(event: 'connection', listener: (socket: Socket) => void): this;
|
---|
| 169 | prependListener(event: 'error', listener: (err: Error) => void): this;
|
---|
| 170 | prependListener(event: 'listening', listener: () => void): this;
|
---|
| 171 | prependListener(event: 'checkContinue', listener: RequestListener): this;
|
---|
| 172 | prependListener(event: 'checkExpectation', listener: RequestListener): this;
|
---|
| 173 | prependListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
|
---|
| 174 | prependListener(event: 'connect', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
|
---|
| 175 | prependListener(event: 'request', listener: RequestListener): this;
|
---|
| 176 | prependListener(event: 'upgrade', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
|
---|
| 177 | prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
---|
| 178 | prependOnceListener(event: 'close', listener: () => void): this;
|
---|
| 179 | prependOnceListener(event: 'connection', listener: (socket: Socket) => void): this;
|
---|
| 180 | prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
---|
| 181 | prependOnceListener(event: 'listening', listener: () => void): this;
|
---|
| 182 | prependOnceListener(event: 'checkContinue', listener: RequestListener): this;
|
---|
| 183 | prependOnceListener(event: 'checkExpectation', listener: RequestListener): this;
|
---|
| 184 | prependOnceListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
|
---|
| 185 | prependOnceListener(event: 'connect', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
|
---|
| 186 | prependOnceListener(event: 'request', listener: RequestListener): this;
|
---|
| 187 | prependOnceListener(event: 'upgrade', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | // https://github.com/nodejs/node/blob/master/lib/_http_outgoing.js
|
---|
| 191 | class OutgoingMessage extends stream.Writable {
|
---|
| 192 | upgrading: boolean;
|
---|
| 193 | chunkedEncoding: boolean;
|
---|
| 194 | shouldKeepAlive: boolean;
|
---|
| 195 | useChunkedEncodingByDefault: boolean;
|
---|
| 196 | sendDate: boolean;
|
---|
| 197 | finished: boolean;
|
---|
| 198 | headersSent: boolean;
|
---|
| 199 | connection: Socket;
|
---|
| 200 |
|
---|
| 201 | constructor();
|
---|
| 202 |
|
---|
| 203 | setTimeout(msecs: number, callback?: () => void): this;
|
---|
| 204 | setHeader(name: string, value: number | string | ReadonlyArray<string>): void;
|
---|
| 205 | getHeader(name: string): number | string | string[] | undefined;
|
---|
| 206 | getHeaders(): OutgoingHttpHeaders;
|
---|
| 207 | getHeaderNames(): string[];
|
---|
| 208 | hasHeader(name: string): boolean;
|
---|
| 209 | removeHeader(name: string): void;
|
---|
| 210 | addTrailers(headers: OutgoingHttpHeaders | ReadonlyArray<[string, string]>): void;
|
---|
| 211 | flushHeaders(): void;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | // https://github.com/nodejs/node/blob/master/lib/_http_server.js#L108-L256
|
---|
| 215 | class ServerResponse extends OutgoingMessage {
|
---|
| 216 | statusCode: number;
|
---|
| 217 | statusMessage: string;
|
---|
| 218 | writableFinished: boolean;
|
---|
| 219 |
|
---|
| 220 | constructor(req: IncomingMessage);
|
---|
| 221 |
|
---|
| 222 | assignSocket(socket: Socket): void;
|
---|
| 223 | detachSocket(socket: Socket): void;
|
---|
| 224 | // https://github.com/nodejs/node/blob/master/test/parallel/test-http-write-callbacks.js#L53
|
---|
| 225 | // no args in writeContinue callback
|
---|
| 226 | writeContinue(callback?: () => void): void;
|
---|
| 227 | writeHead(statusCode: number, statusMessage?: string, headers?: OutgoingHttpHeaders): this;
|
---|
| 228 | writeHead(statusCode: number, headers?: OutgoingHttpHeaders): this;
|
---|
| 229 | writeProcessing(): void;
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | interface InformationEvent {
|
---|
| 233 | statusCode: number;
|
---|
| 234 | statusMessage: string;
|
---|
| 235 | httpVersion: string;
|
---|
| 236 | httpVersionMajor: number;
|
---|
| 237 | httpVersionMinor: number;
|
---|
| 238 | headers: IncomingHttpHeaders;
|
---|
| 239 | rawHeaders: string[];
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | // https://github.com/nodejs/node/blob/v12.20.0/lib/_http_client.js#L85
|
---|
| 243 | class ClientRequest extends OutgoingMessage {
|
---|
| 244 | connection: Socket;
|
---|
| 245 | socket: Socket;
|
---|
| 246 | aborted: boolean;
|
---|
| 247 | host: string;
|
---|
| 248 | protocol: string;
|
---|
| 249 |
|
---|
| 250 | constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void);
|
---|
| 251 |
|
---|
| 252 | method: string;
|
---|
| 253 | readonly path: string;
|
---|
| 254 | abort(): void;
|
---|
| 255 | onSocket(socket: Socket): void;
|
---|
| 256 | setTimeout(timeout: number, callback?: () => void): this;
|
---|
| 257 | setNoDelay(noDelay?: boolean): void;
|
---|
| 258 | setSocketKeepAlive(enable?: boolean, initialDelay?: number): void;
|
---|
| 259 |
|
---|
| 260 | addListener(event: 'abort', listener: () => void): this;
|
---|
| 261 | addListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
---|
| 262 | addListener(event: 'continue', listener: () => void): this;
|
---|
| 263 | addListener(event: 'information', listener: (info: InformationEvent) => void): this;
|
---|
| 264 | addListener(event: 'response', listener: (response: IncomingMessage) => void): this;
|
---|
| 265 | addListener(event: 'socket', listener: (socket: Socket) => void): this;
|
---|
| 266 | addListener(event: 'timeout', listener: () => void): this;
|
---|
| 267 | addListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
---|
| 268 | addListener(event: 'close', listener: () => void): this;
|
---|
| 269 | addListener(event: 'drain', listener: () => void): this;
|
---|
| 270 | addListener(event: 'error', listener: (err: Error) => void): this;
|
---|
| 271 | addListener(event: 'finish', listener: () => void): this;
|
---|
| 272 | addListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
|
---|
| 273 | addListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
|
---|
| 274 | addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
---|
| 275 |
|
---|
| 276 | on(event: 'abort', listener: () => void): this;
|
---|
| 277 | on(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
---|
| 278 | on(event: 'continue', listener: () => void): this;
|
---|
| 279 | on(event: 'information', listener: (info: InformationEvent) => void): this;
|
---|
| 280 | on(event: 'response', listener: (response: IncomingMessage) => void): this;
|
---|
| 281 | on(event: 'socket', listener: (socket: Socket) => void): this;
|
---|
| 282 | on(event: 'timeout', listener: () => void): this;
|
---|
| 283 | on(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
---|
| 284 | on(event: 'close', listener: () => void): this;
|
---|
| 285 | on(event: 'drain', listener: () => void): this;
|
---|
| 286 | on(event: 'error', listener: (err: Error) => void): this;
|
---|
| 287 | on(event: 'finish', listener: () => void): this;
|
---|
| 288 | on(event: 'pipe', listener: (src: stream.Readable) => void): this;
|
---|
| 289 | on(event: 'unpipe', listener: (src: stream.Readable) => void): this;
|
---|
| 290 | on(event: string | symbol, listener: (...args: any[]) => void): this;
|
---|
| 291 |
|
---|
| 292 | once(event: 'abort', listener: () => void): this;
|
---|
| 293 | once(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
---|
| 294 | once(event: 'continue', listener: () => void): this;
|
---|
| 295 | once(event: 'information', listener: (info: InformationEvent) => void): this;
|
---|
| 296 | once(event: 'response', listener: (response: IncomingMessage) => void): this;
|
---|
| 297 | once(event: 'socket', listener: (socket: Socket) => void): this;
|
---|
| 298 | once(event: 'timeout', listener: () => void): this;
|
---|
| 299 | once(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
---|
| 300 | once(event: 'close', listener: () => void): this;
|
---|
| 301 | once(event: 'drain', listener: () => void): this;
|
---|
| 302 | once(event: 'error', listener: (err: Error) => void): this;
|
---|
| 303 | once(event: 'finish', listener: () => void): this;
|
---|
| 304 | once(event: 'pipe', listener: (src: stream.Readable) => void): this;
|
---|
| 305 | once(event: 'unpipe', listener: (src: stream.Readable) => void): this;
|
---|
| 306 | once(event: string | symbol, listener: (...args: any[]) => void): this;
|
---|
| 307 |
|
---|
| 308 | prependListener(event: 'abort', listener: () => void): this;
|
---|
| 309 | prependListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
---|
| 310 | prependListener(event: 'continue', listener: () => void): this;
|
---|
| 311 | prependListener(event: 'information', listener: (info: InformationEvent) => void): this;
|
---|
| 312 | prependListener(event: 'response', listener: (response: IncomingMessage) => void): this;
|
---|
| 313 | prependListener(event: 'socket', listener: (socket: Socket) => void): this;
|
---|
| 314 | prependListener(event: 'timeout', listener: () => void): this;
|
---|
| 315 | prependListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
---|
| 316 | prependListener(event: 'close', listener: () => void): this;
|
---|
| 317 | prependListener(event: 'drain', listener: () => void): this;
|
---|
| 318 | prependListener(event: 'error', listener: (err: Error) => void): this;
|
---|
| 319 | prependListener(event: 'finish', listener: () => void): this;
|
---|
| 320 | prependListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
|
---|
| 321 | prependListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
|
---|
| 322 | prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
---|
| 323 |
|
---|
| 324 | prependOnceListener(event: 'abort', listener: () => void): this;
|
---|
| 325 | prependOnceListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
---|
| 326 | prependOnceListener(event: 'continue', listener: () => void): this;
|
---|
| 327 | prependOnceListener(event: 'information', listener: (info: InformationEvent) => void): this;
|
---|
| 328 | prependOnceListener(event: 'response', listener: (response: IncomingMessage) => void): this;
|
---|
| 329 | prependOnceListener(event: 'socket', listener: (socket: Socket) => void): this;
|
---|
| 330 | prependOnceListener(event: 'timeout', listener: () => void): this;
|
---|
| 331 | prependOnceListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
---|
| 332 | prependOnceListener(event: 'close', listener: () => void): this;
|
---|
| 333 | prependOnceListener(event: 'drain', listener: () => void): this;
|
---|
| 334 | prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
---|
| 335 | prependOnceListener(event: 'finish', listener: () => void): this;
|
---|
| 336 | prependOnceListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
|
---|
| 337 | prependOnceListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
|
---|
| 338 | prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
---|
| 339 | }
|
---|
| 340 |
|
---|
| 341 | class IncomingMessage extends stream.Readable {
|
---|
| 342 | constructor(socket: Socket);
|
---|
| 343 |
|
---|
| 344 | aborted: boolean;
|
---|
| 345 | httpVersion: string;
|
---|
| 346 | httpVersionMajor: number;
|
---|
| 347 | httpVersionMinor: number;
|
---|
| 348 | complete: boolean;
|
---|
| 349 | connection: Socket;
|
---|
| 350 | headers: IncomingHttpHeaders;
|
---|
| 351 | rawHeaders: string[];
|
---|
| 352 | trailers: { [key: string]: string | undefined };
|
---|
| 353 | rawTrailers: string[];
|
---|
| 354 | setTimeout(msecs: number, callback?: () => void): this;
|
---|
| 355 | /**
|
---|
| 356 | * Only valid for request obtained from http.Server.
|
---|
| 357 | */
|
---|
| 358 | method?: string | undefined;
|
---|
| 359 | /**
|
---|
| 360 | * Only valid for request obtained from http.Server.
|
---|
| 361 | */
|
---|
| 362 | url?: string | undefined;
|
---|
| 363 | /**
|
---|
| 364 | * Only valid for response obtained from http.ClientRequest.
|
---|
| 365 | */
|
---|
| 366 | statusCode?: number | undefined;
|
---|
| 367 | /**
|
---|
| 368 | * Only valid for response obtained from http.ClientRequest.
|
---|
| 369 | */
|
---|
| 370 | statusMessage?: string | undefined;
|
---|
| 371 | socket: Socket;
|
---|
| 372 | destroy(error?: Error): void;
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 | interface AgentOptions {
|
---|
| 376 | /**
|
---|
| 377 | * Keep sockets around in a pool to be used by other requests in the future. Default = false
|
---|
| 378 | */
|
---|
| 379 | keepAlive?: boolean | undefined;
|
---|
| 380 | /**
|
---|
| 381 | * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000.
|
---|
| 382 | * Only relevant if keepAlive is set to true.
|
---|
| 383 | */
|
---|
| 384 | keepAliveMsecs?: number | undefined;
|
---|
| 385 | /**
|
---|
| 386 | * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity
|
---|
| 387 | */
|
---|
| 388 | maxSockets?: number | undefined;
|
---|
| 389 | /**
|
---|
| 390 | * Maximum number of sockets allowed for all hosts in total. Each request will use a new socket until the maximum is reached. Default: Infinity.
|
---|
| 391 | */
|
---|
| 392 | maxTotalSockets?: number | undefined;
|
---|
| 393 | /**
|
---|
| 394 | * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256.
|
---|
| 395 | */
|
---|
| 396 | maxFreeSockets?: number | undefined;
|
---|
| 397 | /**
|
---|
| 398 | * Socket timeout in milliseconds. This will set the timeout after the socket is connected.
|
---|
| 399 | */
|
---|
| 400 | timeout?: number | undefined;
|
---|
| 401 | /**
|
---|
| 402 | * Scheduling strategy to apply when picking the next free socket to use. Default: 'fifo'.
|
---|
| 403 | */
|
---|
| 404 | scheduling?: 'fifo' | 'lifo' | undefined;
|
---|
| 405 | }
|
---|
| 406 |
|
---|
| 407 | class Agent {
|
---|
| 408 | maxFreeSockets: number;
|
---|
| 409 | maxSockets: number;
|
---|
| 410 | maxTotalSockets: number;
|
---|
| 411 | readonly sockets: {
|
---|
| 412 | readonly [key: string]: Socket[];
|
---|
| 413 | };
|
---|
| 414 | readonly requests: {
|
---|
| 415 | readonly [key: string]: IncomingMessage[];
|
---|
| 416 | };
|
---|
| 417 |
|
---|
| 418 | constructor(opts?: AgentOptions);
|
---|
| 419 |
|
---|
| 420 | /**
|
---|
| 421 | * Destroy any sockets that are currently in use by the agent.
|
---|
| 422 | * It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled,
|
---|
| 423 | * then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise,
|
---|
| 424 | * sockets may hang open for quite a long time before the server terminates them.
|
---|
| 425 | */
|
---|
| 426 | destroy(): void;
|
---|
| 427 | }
|
---|
| 428 |
|
---|
| 429 | const METHODS: string[];
|
---|
| 430 |
|
---|
| 431 | const STATUS_CODES: {
|
---|
| 432 | [errorCode: number]: string | undefined;
|
---|
| 433 | [errorCode: string]: string | undefined;
|
---|
| 434 | };
|
---|
| 435 |
|
---|
| 436 | function createServer(requestListener?: RequestListener): Server;
|
---|
| 437 | function createServer(options: ServerOptions, requestListener?: RequestListener): Server;
|
---|
| 438 |
|
---|
| 439 | // although RequestOptions are passed as ClientRequestArgs to ClientRequest directly,
|
---|
| 440 | // create interface RequestOptions would make the naming more clear to developers
|
---|
| 441 | interface RequestOptions extends ClientRequestArgs { }
|
---|
| 442 | function request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
|
---|
| 443 | function request(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
|
---|
| 444 | function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
|
---|
| 445 | function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
|
---|
| 446 | let globalAgent: Agent;
|
---|
| 447 |
|
---|
| 448 | /**
|
---|
| 449 | * Read-only property specifying the maximum allowed size of HTTP headers in bytes.
|
---|
| 450 | * Defaults to 8KB. Configurable using the [`--max-http-header-size`][] CLI option.
|
---|
| 451 | */
|
---|
| 452 | const maxHeaderSize: number;
|
---|
| 453 | }
|
---|