From bd51393263919c01b1360e414e141ac5a9fcdaf2 Mon Sep 17 00:00:00 2001 From: Michael Genereux Date: Mon, 5 Oct 2015 18:25:38 -0700 Subject: [PATCH 1/2] Set href as request.js uses it If href was never defined in an original, dynamically generated request options object the rest of the code referencing href fails. --- request.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/request.js b/request.js index af91a11d3..19d5d1644 100644 --- a/request.js +++ b/request.js @@ -247,6 +247,8 @@ Request.prototype.init = function (options) { // If a string URI/URL was given, parse it into a URL object if (typeof self.uri === 'string') { self.uri = url.parse(self.uri) + } else { + self.uri.href = url.format(self.uri) } // DEPRECATED: Warning for users of the old Unix Sockets URL Scheme From 2c1296d7c7154f31af6b88ecd0b7624ffa61567f Mon Sep 17 00:00:00 2001 From: Michael Genereux Date: Tue, 6 Oct 2015 11:06:20 -0700 Subject: [PATCH 2/2] Clarified check and add test. --- request.js | 5 ++++- tests/test-isUrl.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/request.js b/request.js index 19d5d1644..a937047d4 100644 --- a/request.js +++ b/request.js @@ -247,7 +247,10 @@ Request.prototype.init = function (options) { // If a string URI/URL was given, parse it into a URL object if (typeof self.uri === 'string') { self.uri = url.parse(self.uri) - } else { + } + + // 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) } 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()