UNPKG

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