Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fetch parameters not being applied correctly #1870

Merged
merged 5 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1951,8 +1951,6 @@ async function httpNetworkFetch (
body: fetchParams.controller.dispatcher.isMockActive ? request.body && request.body.source : body,
headers: request.headersList[kHeadersCaseInsensitive],
maxRedirections: 0,
bodyTimeout: 300_000,
headersTimeout: 300_000,
xconverge marked this conversation as resolved.
Show resolved Hide resolved
upgrade: request.mode === 'websocket' ? 'websocket' : undefined
},
{
Expand Down
49 changes: 49 additions & 0 deletions test/fetch/fetch-timeouts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict'

const { test } = require('tap')

const { fetch, Agent } = require('../..')
const { createServer } = require('http')
const FakeTimers = require('@sinonjs/fake-timers')

test('Fetch very long request, timeout overridden so no error', (t) => {
const minutes = 6
const msToDelay = 1000 * 60 * minutes

t.setTimeout(undefined)
t.plan(1)

const clock = FakeTimers.install()
t.teardown(clock.uninstall.bind(clock))

const server = createServer((req, res) => {
setTimeout(() => {
res.end('hello')
}, msToDelay)
clock.tick(msToDelay + 1)
})
t.teardown(server.close.bind(server))

server.listen(0, () => {
fetch(`http://localhost:${server.address().port}`, {
path: '/',
method: 'GET',
dispatcher: new Agent({
headersTimeout: 0,
connectTimeout: 0,
bodyTimeout: 0
})
})
.then((response) => response.text())
.then((response) => {
t.equal('hello', response)
t.end()
})
.catch((err) => {
// This should not happen, a timeout error should not occur
t.error(err)
})

clock.tick(msToDelay - 1)
})
})
16 changes: 0 additions & 16 deletions test/node-fetch/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1660,20 +1660,4 @@ 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)
// })
})
16 changes: 0 additions & 16 deletions test/node-fetch/utils/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,22 +227,6 @@ 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')
Expand Down