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): hangs on a stream response with manual redirect #1627

Merged
merged 1 commit into from
Aug 30, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,9 @@ async function httpFetch (fetchParams) {
// and the connection uses HTTP/2, then user agents may, and are even
// encouraged to, transmit an RST_STREAM frame.
// See, https://github.com/whatwg/fetch/issues/1288
fetchParams.controller.connection.destroy()
if (request.redirect !== 'manual') {
fetchParams.controller.connection.destroy()
}

// 2. Switch on request’s redirect mode:
if (request.redirect === 'error') {
Expand Down
28 changes: 28 additions & 0 deletions test/fetch/client-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,34 @@ test('redirect with body', (t) => {
})
})

test('redirect with stream', (t) => {
t.plan(3)

const location = '/asd'
const body = 'hello!'
const server = createServer(async (req, res) => {
res.writeHead(302, { location })
let count = 0
const l = setInterval(() => {
res.write(body[count++])
if (count === body.length) {
res.end()
clearInterval(l)
}
}, 50)
})
t.teardown(server.close.bind(server))

server.listen(0, async () => {
const res = await fetch(`http://localhost:${server.address().port}`, {
redirect: 'manual'
})
t.equal(res.status, 302)
t.equal(res.headers.get('location'), location)
t.equal(await res.text(), body)
})
})

test('fail to extract locked body', (t) => {
t.plan(1)

Expand Down