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 1 commit
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
51 changes: 51 additions & 0 deletions test/fetch/fetch-long.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use strict'

const { test } = require('tap')

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

const minutes = 6
const msToDelay = 1000 * 60 * minutes

const agent = new Agent({
headersTimeout: 0,
connectTimeout: 0,
bodyTimeout: 0
})

test('Long time for a single fetch', (t) => {
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: agent
})
.then((response) => response.text())
.then((response) => {
t.equal('hello', response)
t.end()
})
.catch((err) => {
console.error(err)
t.error(err)
})

clock.tick(msToDelay - 1)
})
})
48 changes: 48 additions & 0 deletions test/fetch/request-long.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict'

const { test } = require('tap')

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

const minutes = 6
const msToDelay = 1000 * 60 * minutes

test('Long time for a single request', (t) => {
t.setTimeout(undefined)

t.plan(2)

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, () => {
const client = new Client(`http://localhost:${server.address().port}`, {
headersTimeout: 0,
connectTimeout: 0
})
t.teardown(client.destroy.bind(client))

client.request({ path: '/', method: 'GET' }, (err, response) => {
t.error(err)
const bufs = []
response.body.on('data', (buf) => {
bufs.push(buf)
})
response.body.on('end', () => {
t.equal('hello', Buffer.concat(bufs).toString('utf8'))
})
})

clock.tick(msToDelay - 1)
})
})