diff --git a/request.js b/request.js index 055c7bfec..2d1cf7ac2 100644 --- a/request.js +++ b/request.js @@ -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) { @@ -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 diff --git a/tests/test-errors.js b/tests/test-errors.js index 56f46bd6e..bfd7c4962 100644 --- a/tests/test-errors.js +++ b/tests/test-errors.js @@ -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({