Pass custom timeout to subsequent requests on redirect (#615)

This commit is contained in:
David Frank 2019-04-27 00:46:53 +08:00 committed by GitHub
parent cfc8e5bad2
commit 49d77600a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View File

@ -153,6 +153,7 @@ export default function fetch(url, opts) {
method: request.method,
body: request.body,
signal: request.signal,
timeout: request.timeout
};
// HTTP-redirect fetch step 9

View File

@ -275,6 +275,14 @@ export default class TestServer {
}, 1000);
}
if (p === '/redirect/slow-chain') {
res.statusCode = 301;
res.setHeader('Location', '/redirect/slow');
setTimeout(function() {
res.end();
}, 100);
}
if (p === '/redirect/slow-stream') {
res.statusCode = 301;
res.setHeader('Location', '/slow');

View File

@ -799,6 +799,17 @@ describe('node-fetch', () => {
});
});
it('should allow custom timeout on redirected requests', function() {
this.timeout(2000);
const url = `${base}redirect/slow-chain`;
const opts = {
timeout: 200
};
return expect(fetch(url, opts)).to.eventually.be.rejected
.and.be.an.instanceOf(FetchError)
.and.have.property('type', 'request-timeout');
});
it('should clear internal timeout on fetch response', function (done) {
this.timeout(2000);
spawn('node', ['-e', `require('./')('${base}hello', { timeout: 10000 })`])