diff --git a/index.js b/index.js index b42a807..21d1714 100644 --- a/index.js +++ b/index.js @@ -148,7 +148,11 @@ function got(url, opts, cb) { } var redirectUrl = urlLib.resolve(url, res.headers.location); - var redirectOpts = objectAssign(opts, urlLib.parse(redirectUrl)); + var redirectOpts = objectAssign({}, opts, urlLib.parse(redirectUrl)); + + if (opts.agent === infinityAgent.http.globalAgent && redirectOpts.protocol === 'https:' && opts.protocol === 'http:') { + redirectOpts.agent = undefined; + } if (proxy) { proxy.emit('redirect', res, redirectOpts); diff --git a/test/test-https.js b/test/test-https.js index 594820e..8e6560d 100644 --- a/test/test-https.js +++ b/test/test-https.js @@ -55,6 +55,14 @@ test('setup', function (t) { }); }); +test('redirects from http to https works', function (t) { + got('http://github.com', function (err, data) { + t.error(err); + t.ok(data); + t.end(); + }); +}); + test('make request to https server', function (t) { got('https://google.com', { strictSSL: true