Skip to content

Commit

Permalink
Reselect agent on redirect from http to https
Browse files Browse the repository at this point in the history
Closes #80
  • Loading branch information
floatdrop committed Jul 14, 2015
1 parent 75cbd91 commit b9c33aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions test/test-https.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b9c33aa

Please sign in to comment.