Browse Source

Reselect agent on redirect from http to https

Closes #80
http2
Vsevolod Strukchinsky 10 years ago
parent
commit
b9c33aa64e
  1. 6
      index.js
  2. 8
      test/test-https.js

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

8
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

Loading…
Cancel
Save