Skip to content

Commit

Permalink
Merge pull request #613 from lexander/master
Browse files Browse the repository at this point in the history
Fixes #583, moved initialization of self.uri.pathname
  • Loading branch information
mikeal committed Aug 1, 2013
2 parents 08793ec + cce2c2c commit cfd5c9a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function copy (obj) {
return o
}

var isUrl = /^https?:/
var isUrl = /^https?:/i

var globalPool = {}

Expand Down Expand Up @@ -188,8 +188,10 @@ Request.prototype.init = function (options) {
self.tunnel = true
}
}

if (!self.uri.pathname) {self.uri.pathname = '/'}

if (!self.uri.host || !self.uri.pathname) {
if (!self.uri.host) {
// Invalid URI: it may generate lot of bad errors, like "TypeError: Cannot call method 'indexOf' of undefined" in CookieJar
// Detect and reject it as soon as possible
var faultyUri = url.format(self.uri)
Expand Down Expand Up @@ -226,7 +228,6 @@ Request.prototype.init = function (options) {

self.jar(self._jar || options.jar)

if (!self.uri.pathname) {self.uri.pathname = '/'}
if (!self.uri.port) {
if (self.uri.protocol == 'http:') {self.uri.port = 80}
else if (self.uri.protocol == 'https:') {self.uri.port = 443}
Expand Down
28 changes: 28 additions & 0 deletions tests/test-isUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var assert = require('assert')
, request = require('../index')
, http = require('http')
;

var s = http.createServer(function(req, res) {
res.statusCode = 200;
res.end('');
}).listen(6767, function () {

// Test lowercase
request('http://localhost:6767', function (err, resp, body) {
// just need to get here without throwing an error
assert.equal(true, true);
})

// Test uppercase
request('HTTP://localhost:6767', function (err, resp, body) {
assert.equal(true, true);
})

// Test mixedcase
request('HtTp://localhost:6767', function (err, resp, body) {
assert.equal(true, true);
// clean up
s.close();
})
})

0 comments on commit cfd5c9a

Please sign in to comment.