diff --git a/request.js b/request.js index 824f9386e..f4311d801 100644 --- a/request.js +++ b/request.js @@ -249,6 +249,11 @@ Request.prototype.init = function (options) { self.uri = url.parse(self.uri) } + // Some URL objects are not from a URL parsed string and need href added + if (!self.uri.href) { + self.uri.href = url.format(self.uri) + } + // DEPRECATED: Warning for users of the old Unix Sockets URL Scheme if (self.uri.protocol === 'unix:') { return self.emit('error', new Error('`unix://` URL scheme is no longer supported. Please use the format `http://unix:SOCKET:PATH`')) diff --git a/tests/test-isUrl.js b/tests/test-isUrl.js index c6b930ddc..0623eac4b 100644 --- a/tests/test-isUrl.js +++ b/tests/test-isUrl.js @@ -94,6 +94,23 @@ tape('hostname and port 3', function(t) { }) }) +tape('hostname and query string', function(t) { + request({ + uri: { + protocol: 'http:', + hostname: 'localhost', + port: 6767 + }, + qs: { + test: 'test' + } + }, function(err, res, body) { + t.equal(err, null) + t.equal(body, 'ok') + t.end() + }) +}) + tape('cleanup', function(t) { s.close(function() { t.end()