Skip to content

Commit

Permalink
Fixed optional schema support. Closes #49
Browse files Browse the repository at this point in the history
url.parse() would give you a schema of "localhost:" haha
  • Loading branch information
tj committed Jan 14, 2012
1 parent 4105018 commit 4711163
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,14 @@ Request.prototype.auth = function(user, pass){

Request.prototype.request = function(){
if (this.req) return this.req;

var self = this
, options = this.options || {}
, data = this._data || null
, url = parse(this.url);
, url = this.url;

// default to http://
if (0 != url.indexOf('http')) url = 'http://' + url;
url = parse(url);

// options
options.method = this.method;
Expand All @@ -507,7 +510,7 @@ Request.prototype.request = function(){
}

// initiate request
var mod = exports.protocols[url.protocol || 'http:'];
var mod = exports.protocols[url.protocol];

// request
var req = this.req = mod.request(options);
Expand Down
11 changes: 11 additions & 0 deletions test/node/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ describe('request', function(){
})
})

describe('without a schema', function(){
it('should default to http', function(done){
request
.get('localhost:3000/login')
.end(function(res){
assert(res.status == 200);
done();
})
})
})

describe('.end()', function(){
it('should issue a request', function(done){
request
Expand Down

0 comments on commit 4711163

Please sign in to comment.