Permalink
Browse files

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.
  • Loading branch information...
1 parent 0a5d8ca commit f3189ace6b5e31a874df421ac2f74da0e77cb14d @TooTallNate TooTallNate committed Feb 25, 2014
Showing with 0 additions and 42 deletions.
  1. +0 −42 lib/_http_agent.js
View
@@ -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();

0 comments on commit f3189ac

Please sign in to comment.