Browse Source

http: remove the circular dependency

Between `ClientRequest` and `Agent`. The circular require was doing
weird things at load time, like making the `globalAgent` property
be `undefined` from within the context of the "_http_client"
module.

Removing the circular dependency completely fixes this.

This commit effectively removes the undocumented `Agent#request()`
and `Agent#get()` functions.
v0.11.12-release
Nathan Rajlich 11 years ago
parent
commit
f3189ace6b
  1. 42
      lib/_http_agent.js

42
lib/_http_agent.js

@ -20,10 +20,8 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var net = require('net');
var url = require('url');
var util = require('util');
var EventEmitter = require('events').EventEmitter;
var ClientRequest = require('_http_client').ClientRequest;
var debug = util.debuglog('http');
// New Agent code.
@ -267,44 +265,4 @@ Agent.prototype.destroy = function() {
});
};
Agent.prototype.request = function(options, cb) {
if (util.isString(options)) {
options = url.parse(options);
}
// don't try to do dns lookups of foo.com:8080, just foo.com
if (options.hostname) {
options.host = options.hostname;
}
if (options && options.path && / /.test(options.path)) {
// The actual regex is more like /[^A-Za-z0-9\-._~!$&'()*+,;=/:@]/
// with an additional rule for ignoring percentage-escaped characters
// but that's a) hard to capture in a regular expression that performs
// well, and b) possibly too restrictive for real-world usage. That's
// why it only scans for spaces because those are guaranteed to create
// an invalid request.
throw new TypeError('Request path contains unescaped characters.');
} else if (options.protocol && options.protocol !== this.protocol) {
throw new Error('Protocol:' + options.protocol + ' not supported.');
}
options = util._extend({
agent: this,
keepAlive: this.keepAlive
}, options);
// if it's false, then make a new one, just like this one.
if (options.agent === false)
options.agent = new this.constructor();
debug('agent.request', options);
return new ClientRequest(options, cb);
};
Agent.prototype.get = function(options, cb) {
var req = this.request(options, cb);
req.end();
return req;
};
exports.globalAgent = new Agent();

Loading…
Cancel
Save