Skip to content

Commit

Permalink
Merge pull request DefinitelyTyped#3787 from rogierschouten/node-http…
Browse files Browse the repository at this point in the history
…-agent

Add http.Agent to node.js typings
  • Loading branch information
vvakame committed Mar 5, 2015
2 parents fcc7f7f + 3699358 commit 168d74e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
37 changes: 36 additions & 1 deletion node/node-0.10.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions node/node-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

////////////////////////////////////////////////////
Expand Down
37 changes: 36 additions & 1 deletion node/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 168d74e

Please sign in to comment.