UNPKG

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