@@ -412,7 +412,7 @@ declare module "http" {
412
412
[ header : string ] : string | string [ ] ;
413
413
}
414
414
415
- export interface Server extends events . EventEmitter {
415
+ export class Server extends events . EventEmitter {
416
416
listen ( port : number , hostname ?: string , backlog ?: number , callback ?: Function ) : Server ;
417
417
listen ( path : string , callback ?: Function ) : Server ;
418
418
listen ( handle : any , listeningListener ?: Function ) : Server ;
@@ -421,7 +421,7 @@ declare module "http" {
421
421
maxHeadersCount : number ;
422
422
}
423
423
424
- export interface IncomingMessage extends events . EventEmitter , stream . Readable {
424
+ export class IncomingMessage extends stream . Readable {
425
425
httpVersion : string ;
426
426
headers : IncomingHeaders ;
427
427
rawHeaders : string [ ] ;
@@ -447,7 +447,7 @@ declare module "http" {
447
447
socket : net . Socket ;
448
448
}
449
449
450
- export interface ServerResponse extends events . EventEmitter , stream . Writable {
450
+ export class ServerResponse extends stream . Writable {
451
451
// Extended base methods
452
452
write ( buffer : Buffer ) : boolean ;
453
453
write ( buffer : Buffer , cb ?: Function ) : boolean ;
@@ -460,6 +460,7 @@ declare module "http" {
460
460
writeHead ( statusCode : number , headers ?: OutgoingHeaders ) : void ;
461
461
statusCode : number ;
462
462
setHeader ( name : string , value : string ) : void ;
463
+ setTimeout ( msecs : number , callback : ( ) => void ) : this;
463
464
sendDate : boolean ;
464
465
getHeader ( name : string ) : string ;
465
466
removeHeader ( name : string ) : void ;
@@ -473,33 +474,33 @@ declare module "http" {
473
474
end ( str : string , encoding ?: string , cb ?: Function ) : void ;
474
475
}
475
476
476
- /**
477
- * Object returned by http.request()
478
- */
479
- export interface ClientRequest extends events . EventEmitter , stream . Writable {
477
+ /**
478
+ * Object returned by http.request()
479
+ */
480
+ export class ClientRequest extends stream . Writable {
480
481
abort ( ) : void ;
481
482
setTimeout ( timeout : number , callback ?: Function ) : void ;
482
483
setNoDelay ( noDelay ?: boolean ) : void ;
483
484
setSocketKeepAlive ( enable ?: boolean , initialDelay ?: number ) : void ;
484
485
}
485
486
486
487
export interface AgentOptions {
487
- /**
488
- * Keep sockets around in a pool to be used by other requests in the future. Default = false
489
- */
488
+ /**
489
+ * Keep sockets around in a pool to be used by other requests in the future. Default = false
490
+ */
490
491
keepAlive ?: boolean ;
491
- /**
492
- * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000.
493
- * Only relevant if keepAlive is set to true.
494
- */
492
+ /**
493
+ * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000.
494
+ * Only relevant if keepAlive is set to true.
495
+ */
495
496
keepAliveMsecs ?: number ;
496
- /**
497
- * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity
498
- */
497
+ /**
498
+ * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity
499
+ */
499
500
maxSockets ?: number ;
500
- /**
501
- * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256.
502
- */
501
+ /**
502
+ * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256.
503
+ */
503
504
maxFreeSockets ?: number ;
504
505
}
505
506
@@ -510,68 +511,69 @@ declare module "http" {
510
511
511
512
constructor ( opts ?: AgentOptions ) ;
512
513
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
- */
514
+ /**
515
+ * Destroy any sockets that are currently in use by the agent.
516
+ * It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled,
517
+ * then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise,
518
+ * sockets may hang open for quite a long time before the server terminates them.
519
+ */
519
520
destroy ( ) : void ;
520
521
}
521
522
522
- /**
523
- * Options for http.request()
524
- */
523
+ /**
524
+ * Options for http.request()
525
+ */
525
526
export interface RequestOptions {
526
- /**
527
- * A domain name or IP address of the server to issue the request to. Defaults to 'localhost'.
528
- */
527
+ /**
528
+ * A domain name or IP address of the server to issue the request to. Defaults to 'localhost'.
529
+ */
529
530
host ?: string ;
530
- /**
531
- * To support url.parse() hostname is preferred over host
532
- */
531
+ /**
532
+ * To support url.parse() hostname is preferred over host
533
+ */
533
534
hostname ?: string ;
534
- /**
535
- * Port of remote server. Defaults to 80.
536
- */
535
+ /**
536
+ * Port of remote server. Defaults to 80.
537
+ */
537
538
port ?: number | string ;
538
- /**
539
- * Local interface to bind for network connections.
540
- */
539
+ /**
540
+ * Local interface to bind for network connections.
541
+ */
541
542
localAddress ?: string ;
542
- /**
543
- * Unix Domain Socket (use one of host:port or socketPath)
544
- */
543
+ /**
544
+ * Unix Domain Socket (use one of host:port or socketPath)
545
+ */
545
546
socketPath ?: string ;
546
- /**
547
- * A string specifying the HTTP request method. Defaults to 'GET'.
548
- */
547
+ /**
548
+ * A string specifying the HTTP request method. Defaults to 'GET'.
549
+ */
549
550
method ?: string ;
550
- /**
551
- * Request path. Defaults to '/'. Should include query string if any. E.G. '/index.html?page=12'
552
- */
551
+ /**
552
+ * Request path. Defaults to '/'. Should include query string if any. E.G. '/index.html?page=12'
553
+ */
553
554
path ?: string ;
554
- /**
555
- * An object containing request headers.
556
- */
555
+ /**
556
+ * An object containing request headers.
557
+ */
557
558
headers ?: OutgoingHeaders ;
558
- /**
559
- * Basic authentication i.e. 'user:password' to compute an Authorization header.
560
- */
559
+ /**
560
+ * Basic authentication i.e. 'user:password' to compute an Authorization header.
561
+ */
561
562
auth ?: string ;
562
- /**
563
- * Controls Agent behavior. When an Agent is used request will default to Connection: keep-alive. Possible values:
564
- * - undefined (default): use global Agent for this host and port.
565
- * - Agent object: explicitly use the passed in Agent.
566
- * - false: opts out of connection pooling with an Agent, defaults request to Connection: close.
567
- */
563
+ /**
564
+ * Controls Agent behavior. When an Agent is used request will default to Connection: keep-alive. Possible values:
565
+ * - undefined (default): use global Agent for this host and port.
566
+ * - Agent object: explicitly use the passed in Agent.
567
+ * - false: opts out of connection pooling with an Agent, defaults request to Connection: close.
568
+ */
568
569
agent ?: Agent | boolean ;
569
570
}
570
571
571
572
export var STATUS_CODES : {
572
573
[ errorCode : number ] : string ;
573
574
[ errorCode : string ] : string ;
574
575
} ;
576
+
575
577
export function createServer ( requestListener ?: ( request : IncomingMessage , response : ServerResponse ) => void ) : Server ;
576
578
export function createClient ( port ?: number , host ?: string ) : any ;
577
579
export function request ( options : string | RequestOptions , callback ?: ( response : IncomingMessage ) => void ) : ClientRequest ;
0 commit comments