Browse Source

fix query option on redirect

http2
Vsevolod Strukchinsky 10 years ago
parent
commit
1e5993a799
  1. 1
      index.js
  2. 15
      test/test-redirects.js

1
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) {

15
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);

Loading…
Cancel
Save