From 369935805c148d1d640fc483d41bed0fb2e38dee Mon Sep 17 00:00:00 2001 From: Rogier Schouten Date: Wed, 4 Mar 2015 13:57:57 +0100 Subject: [PATCH] Add http.Agent to node.js typings --- node/node-0.10.d.ts | 37 ++++++++++++++++++++++++++++++++++++- node/node-tests.ts | 9 +++++++++ node/node.d.ts | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/node/node-0.10.d.ts b/node/node-0.10.d.ts index 99ab5eccd0..28f0a3bc5c 100644 --- a/node/node-0.10.d.ts +++ b/node/node-0.10.d.ts @@ -349,7 +349,42 @@ declare module "http" { pause(): void; resume(): void; } - export interface Agent { maxSockets: number; sockets: any; requests: any; } + + export interface AgentOptions { + /** + * Keep sockets around in a pool to be used by other requests in the future. Default = false + */ + keepAlive?: boolean; + /** + * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000. + * Only relevant if keepAlive is set to true. + */ + keepAliveMsecs?: number; + /** + * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity + */ + maxSockets?: number; + /** + * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256. + */ + maxFreeSockets?: number; + } + + export class Agent { + maxSockets: number; + sockets: any; + requests: any; + + constructor(opts?: AgentOptions); + + /** + * Destroy any sockets that are currently in use by the agent. + * It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled, + * then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise, + * sockets may hang open for quite a long time before the server terminates them. + */ + destroy(): void; + } export var STATUS_CODES: { [errorCode: number]: string; diff --git a/node/node-tests.ts b/node/node-tests.ts index f2702ec4a8..b50e01f272 100644 --- a/node/node-tests.ts +++ b/node/node-tests.ts @@ -154,6 +154,15 @@ module http_tests { var code = 100; var codeMessage = http.STATUS_CODES['400']; var codeMessage = http.STATUS_CODES[400]; + + var agent: http.Agent = new http.Agent({ + keepAlive: true, + keepAliveMsecs: 10000, + maxSockets: Infinity, + maxFreeSockets: 256 + }); + + var agent: http.Agent = http.globalAgent; } //////////////////////////////////////////////////// diff --git a/node/node.d.ts b/node/node.d.ts index deae056a1e..2229637152 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -349,7 +349,42 @@ declare module "http" { pause(): void; resume(): void; } - export interface Agent { maxSockets: number; sockets: any; requests: any; } + + export interface AgentOptions { + /** + * Keep sockets around in a pool to be used by other requests in the future. Default = false + */ + keepAlive?: boolean; + /** + * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000. + * Only relevant if keepAlive is set to true. + */ + keepAliveMsecs?: number; + /** + * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity + */ + maxSockets?: number; + /** + * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256. + */ + maxFreeSockets?: number; + } + + export class Agent { + maxSockets: number; + sockets: any; + requests: any; + + constructor(opts?: AgentOptions); + + /** + * Destroy any sockets that are currently in use by the agent. + * It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled, + * then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise, + * sockets may hang open for quite a long time before the server terminates them. + */ + destroy(): void; + } export var STATUS_CODES: { [errorCode: number]: string;