Skip to content

Commit

Permalink
Merge pull request #1599 from simov/invalid-uri-no-proxy
Browse files Browse the repository at this point in the history
Move getProxyFromURI logic below the check for Invaild URI (#1595)
  • Loading branch information
simov committed May 26, 2015
2 parents ee6ff62 + a15463c commit 3733c61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
18 changes: 9 additions & 9 deletions request.js
Expand Up @@ -444,15 +444,6 @@ Request.prototype.init = function (options) {
self.rejectUnauthorized = false
}

if (!self.hasOwnProperty('proxy')) {
self.proxy = getProxyFromURI(self.uri)
}

self.tunnel = getTunnelOption(self, options)
if (self.proxy) {
self.setupTunnel()
}

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

if (!(self.uri.host || (self.uri.hostname && self.uri.port)) && !self.uri.isUnix) {
Expand All @@ -470,6 +461,15 @@ Request.prototype.init = function (options) {
return self.emit('error', new Error(message))
}

if (!self.hasOwnProperty('proxy')) {
self.proxy = getProxyFromURI(self.uri)
}

self.tunnel = getTunnelOption(self, options)
if (self.proxy) {
self.setupTunnel()
}

self._redirect.onRequest(options)

self.setHost = false
Expand Down
11 changes: 11 additions & 0 deletions tests/test-errors.js
Expand Up @@ -30,6 +30,17 @@ tape('invalid uri 2', function(t) {
t.end()
})

tape('invalid uri + NO_PROXY', function(t) {
process.env.NO_PROXY = 'google.com'
t.throws(function() {
request({
uri: 'invalid'
})
}, /^Error: Invalid URI/)
delete process.env.NO_PROXY
t.end()
})

tape('deprecated unix URL', function(t) {
t.throws(function() {
request({
Expand Down

0 comments on commit 3733c61

Please sign in to comment.