Skip to content

Commit

Permalink
fix(fetch): hangs on a stream response with manual redirect (#1627)
Browse files Browse the repository at this point in the history
  • Loading branch information
feugy committed Aug 30, 2022
1 parent 03cfc4b commit 89a340f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
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

0 comments on commit 89a340f

Please sign in to comment.