diff --git a/lib/fetch/index.js b/lib/fetch/index.js index c4ec1faf5b3..ec1503c159e 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -1920,7 +1920,9 @@ async function httpNetworkFetch ( method: request.method, body: fetchParams.controller.dispatcher[kIsMockActive] ? request.body && request.body.source : body, headers: [...request.headersList].flat(), - maxRedirections: 0 + maxRedirections: 0, + bodyTimeout: 300_000, + headersTimeout: 300_000 }, { body: null, diff --git a/test/node-fetch/main.js b/test/node-fetch/main.js index 77a61a29454..a6d1501f40d 100644 --- a/test/node-fetch/main.js +++ b/test/node-fetch/main.js @@ -1641,4 +1641,20 @@ describe('node-fetch', () => { expect(res.ok).to.be.false }) }) + + // it('should not time out waiting for a response 60 seconds', function () { + // this.timeout(65_000) + // return fetch(`${base}timeout60s`).then(res => { + // expect(res.status).to.equal(200) + // expect(res.ok).to.be.true + // return res.text().then(result => { + // expect(result).to.equal('text') + // }) + // }) + // }) + + // it('should time out waiting for more than 300 seconds', function () { + // this.timeout(305_000) + // return expect(fetch(`${base}timeout300s`)).to.eventually.be.rejectedWith(TypeError) + // }) }) diff --git a/test/node-fetch/utils/server.js b/test/node-fetch/utils/server.js index a2817a2d30b..97b551582bd 100644 --- a/test/node-fetch/utils/server.js +++ b/test/node-fetch/utils/server.js @@ -227,6 +227,22 @@ module.exports = class TestServer { }, 1000) } + if (p === '/timeout60s') { + setTimeout(() => { + res.statusCode = 200 + res.setHeader('Content-Type', 'text/plain') + res.end('text') + }, 60_000) + } + + if (p === '/timeout300s') { + setTimeout(() => { + res.statusCode = 200 + res.setHeader('Content-Type', 'text/plain') + res.end('text') + }, 300_000) + } + if (p === '/slow') { res.statusCode = 200 res.setHeader('Content-Type', 'text/plain')