request / forever-agent Goto Github PK
View Code? Open in Web Editor NEWHTTP Agent that keeps socket connections alive between keep-alive requests. Formerly part of mikeal/request, now a standalone module.
License: Apache License 2.0
HTTP Agent that keeps socket connections alive between keep-alive requests. Formerly part of mikeal/request, now a standalone module.
License: Apache License 2.0
When investigating why connections were being created and destroyed constantly I noticed that forever-agent looks at the request's useChunkedEncodingByDefault
property rather than it's chunkedEncoding
property, which seems to actually say if the request is chunked or not. Is there a reason for this?
In this screenshot you can see:
I am using it with newer version of node and facing problem with following code of getConnectionName function in index.js.
name = host.host + ':' + host.port + ':' + (host.localAddress ? (host.localAddress + ':') : ':')
Why appending 2 colons after port number when localAddress is not present.
name getting created for my following host object is "abcd.com:80::"
{ path: undefined,
port: 80,
host: 'abcd.com',
minSockets: 10,
maxSockets: 100,
servername: 'abcd.com',
_agentKey: 'abcd.com:80:',
encoding: null
}
ForeverAgent has a addRequest
method, and also an addRequestnoreuse
method. This overrides the http.Agent's addRequest
method.
I'd really like to change the signature of agent.addRequest
so that it takes an options object rather than a set of positional arguments. The reason for this is that it would allow us to reuse more of the code between http and https, where there are many more things that separate reusability buckets than just the host and port. You can reuse connections with https, but only if all the following fields are matching: host, port, ca, cert, ciphers, key, passphrase, pfx, and rejectUnauthorized.
However, because request and forever-agent use this undocumented API, we can't change it, and it'll break on the upgrade to 0.12. Making things worse, you can't chnage forever-agent's API, because request dives into its guts and sniffs for a addRequestnoreuse
method.
Is there any way to refactor this so that it doesn't rely on internals in this way? What if I open source the new 0.12 http.Agent that has built-in keepAlive if you turn it on?
While using let's say ForeverAgent({maxSockets: 5}) is clear (allocate up to 5 sockets), in order to create a pool with exactly one socket I need to pass options {maxSockets: 1, minSockets: 2} as minSockets means something like "minimal amount of sockets to be kept in the pool" + 1.
Changing < to <= in https://github.com/mikeal/forever-agent/blob/master/index.js#L22 will fix it, however I understand that doing that will affect current users, so if that is not possible clarification in the doc will be good enough.
Just wanted to be clear that this module is intended to use the keep alive connection for multiple requests, thus using fewer sockets on the machine?
Raise Protocol http: not supported
error under node 0.11.
See details in joyent/node/_http_client.js#L63 and joyent/node/_http_client.js#L73
The constructor has this:
self.on('free', function(socket, host, port) { //...etc
EventEmitter is not in the prototype chain so it errors:
Object #<Object> has no method 'on'
why is there no package.json ? how did you upload it to npm without a package.json ? either i am missing something or you forgot to upload package.json ?
What would be the best way to call socket.setTimeout?
This would be from the request level, i.e.,
var request = require('request')
request.agent.timeout = 30 * 1000
I have the following case:
var request = require('request');
var ForeverAgent = require('forever-agent');
var agent = new ForeverAgent();
request("http://playertest.longtailvideo.com/adaptive/wowzaid3/playlist.m3u8", {agent:agent}, function(err, response){
console.log(err);
console.log(response);
console.log(err);
});
request("http://playertest.longtailvideo.com/adaptive/wowzaid3/playlist.m3u8", function(err, response){
console.log(err);
console.log(response);
console.log(err);
});
In the first request block I get the following error:
{ [Error: connect ENOENT /adaptive/wowzaid3/playlist.m3u8]
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'connect',
address: '/adaptive/wowzaid3/playlist.m3u8' }
While the second without forever agent returns a response as expected. I believe this is an issue with ForeverAgent, unless my implementation or understanding of ForeverAgent's use is wrong here?
I want to use "oauth-sign" but the Copyright phrase is not specified. Please update the Copyright phrase on the source code.
To close all remaining free sockets, thoughts @simov?
Hi
For a specific test, we need to make sure that two subsequent requests use the same connection.
So, I use forever-agent with request module and it works great if the two requests are GET.
Now if the second request is a POST, the second request is never sent and it blocks forever.
After some investigations, I see that in the pb is in 'addRequest':
in the case of POST, the code does not enter the logic to reuse socket, but calls parent method addRequestNoreuse.
The reason is the test on 'req.useChunkedEncodingByDefault', which is set to true in case of a POST.
if (this.freeSockets[name] && this.freeSockets[name].length > 0
&& !req.useChunkedEncodingByDefault) {
If I remove this test, it works fine.
So, of course I could patch the forever-agent to do what I want, but I was wondering
Thanks
Yann
this module is referenced from https://github.com/request/request, however I can't really understand how to use it
I have a rather weird setup and I am unsure where to report this.
I am using orientjs driver that apparently has something to do with forever but don't know what exactly since it's just a module.
My program runs fine with just nodemon but if I try to debug with bode-debug (frontend for node-inspector and babel) I get this:
Debugger listening on port 5858
/home/aris/code/social/server/node_modules/orientjs/node_modules/request/node_modules/forever-agent/index.js:97
ForeverAgentSSL.prototype.addRequestNoreuse = AgentSSL.prototype.addRequest
^
TypeError: Cannot read property 'prototype' of undefined
at Object. (/home/aris/code/social/server/node_modules/orientjs/node_modules/request/node_modules/forever-agent/index.js:97:55)
at Module._compile (module.js:460:26)
at Module._extensions..js (module.js:478:10)
at Object.require.extensions.(anonymous function) as .js
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object. (/home/aris/code/social/server/node_modules/orientjs/node_modules/request/request.js:21:20)
at Module._compile (module.js:460:26)
at Module._extensions..js (module.js:478:10)
at Object.require.extensions.(anonymous function) as .js
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
is it possible to use open socket in POST requests? using 'request' library?
works fine for 'GET' requests, but doesn't work for POST requests
Forever-agent:
function getConnectionName(host, port) {
var name = ''
if (typeof host === 'string') {
name = host + ':' + port
} else {
// For node.js v012.0 and iojs-v1.5.1, host is an object. And any existing localAddress is part of the connection name.
name = host.host + ':' + host.port + ':' + (host.localAddress ? (host.localAddress + ':') : ':')
}
return name
}
_http_agent:
Agent.prototype.getName = function(options) {
var name = options.host || 'localhost';
name +=':';
if (options.port) name += options.port;
name += ':';
if (options.localAddress) name += options.localAddress;
if (options.family === 4 || options.family === 6)
name += ':' + options.family;
return name;
};
Here, given the parameter 'host' in forever-agent.getConnectionName() is object, then:
The difference between these two functions will cause the forever-agent throws the error:
TypeError: Cannot read property 'length' of undefined,
at ForeverAgent/index.js:34:34
because self.sockets[name] is undefined.
Should we change to be:
name = host.host + ':' + host.port + ':' + (host.localAddress ? host.localAddress : '');
name += (host.family === 4 || host.family === 6) ? ( ':' + host.family) : '';
like zero - none
README plz?
UNCAUGHT EXCEPTION: 'TypeError: Cannot set property 'port' of undefined\n at ForeverAgentSSL.createConnectionSSL as createConnection\n at ForeverAgentSSL.Agent.createSocket (http.js:1158:16)\n at ForeverAgentSSL.Agent.addRequest as addRequestNoreuse\n at ForeverAgentSSL.ForeverAgent.addRequest (/Users/nravicha/dev/mobile-server/node_modules/request/forever.js:58:10)\n at new ClientRequest (http.js:1279:16)\n at Object.exports.request (https.js:105:10)\n at Request.start (/Users/nravicha/dev/mobile-server/node_modules/request/main.js:559:30)\n at Request.end (/Users/nravicha/dev/mobile-server/node_modules/request/main.js:1075:28)\n at Request.init (/Users/nravicha/dev/mobile-server/node_modules/request/main.js:402:12)\n at process.startup.processNextTick.process._tickCallback (node.js:244:9)'
On debugging, I found that createConnectionSSL(port, host , options)
is being called with options as the first and only argument. port and host are already part of options as follows:
createConnectionSSL(options)
Thus, the third argument is undefined and causes the crash.
Changing function signature to createConnectionSSL (options) makes it work without issues
Any issues with adding or making an MIT license for this package?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.