Pass custom timeout to subsequent requests on redirect (#615)
This commit is contained in:
parent
cfc8e5bad2
commit
49d77600a7
|
@ -153,6 +153,7 @@ export default function fetch(url, opts) {
|
||||||
method: request.method,
|
method: request.method,
|
||||||
body: request.body,
|
body: request.body,
|
||||||
signal: request.signal,
|
signal: request.signal,
|
||||||
|
timeout: request.timeout
|
||||||
};
|
};
|
||||||
|
|
||||||
// HTTP-redirect fetch step 9
|
// HTTP-redirect fetch step 9
|
||||||
|
|
|
@ -275,6 +275,14 @@ export default class TestServer {
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p === '/redirect/slow-chain') {
|
||||||
|
res.statusCode = 301;
|
||||||
|
res.setHeader('Location', '/redirect/slow');
|
||||||
|
setTimeout(function() {
|
||||||
|
res.end();
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
if (p === '/redirect/slow-stream') {
|
if (p === '/redirect/slow-stream') {
|
||||||
res.statusCode = 301;
|
res.statusCode = 301;
|
||||||
res.setHeader('Location', '/slow');
|
res.setHeader('Location', '/slow');
|
||||||
|
|
11
test/test.js
11
test/test.js
|
@ -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) {
|
it('should clear internal timeout on fetch response', function (done) {
|
||||||
this.timeout(2000);
|
this.timeout(2000);
|
||||||
spawn('node', ['-e', `require('./')('${base}hello', { timeout: 10000 })`])
|
spawn('node', ['-e', `require('./')('${base}hello', { timeout: 10000 })`])
|
||||||
|
|
Loading…
Reference in New Issue