From 1e5993a79903f4d87035bef0e7fd14876205ff29 Mon Sep 17 00:00:00 2001 From: Vsevolod Strukchinsky Date: Sun, 26 Apr 2015 22:59:24 +0500 Subject: [PATCH] fix query option on redirect --- index.js | 1 + test/test-redirects.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/index.js b/index.js index 4b462f2..0f16f40 100644 --- a/index.js +++ b/index.js @@ -103,6 +103,7 @@ function got(url, opts, cb) { if (query) { arg.path = (arg.path ? arg.path.split('?')[0] : '') + '?' + (typeof query === 'string' ? query : querystring.stringify(query)); + query = undefined; } var req = fn.request(arg, function (response) { diff --git a/test/test-redirects.js b/test/test-redirects.js index 829ffee..40e9515 100644 --- a/test/test-redirects.js +++ b/test/test-redirects.js @@ -25,6 +25,13 @@ s.on('/relative', function (req, res) { res.end(); }); +s.on('/relativeQuery?bang', function (req, res) { + res.writeHead(302, { + location: '/' + }); + res.end(); +}); + s.on('/', function (req, res) { res.end('reached'); }); @@ -59,6 +66,14 @@ tape('throws on endless redirect', function (t) { }); }); +tape('query in options are not breaking redirects', function (t) { + got(s.url + '/relativeQuery', {query: 'bang'}, function (err, data) { + t.error(err); + t.equal(data, 'reached'); + t.end(); + }); +}); + tape('host+path in options are not breaking redirects', function (t) { got(s.url + '/relative', {host: s.url, path: '/relative'}, function (err, data) { t.error(err);