Skip to content

Commit

Permalink
fix: header sent but not destroyed should be destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
唐烨 committed Nov 17, 2023
1 parent e1625e6 commit 72cdce6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,17 @@ export const getRequestListener = (fetchCallback: FetchCallback) => {
}

// do not write response if outgoing is already finished
if (outgoing.destroyed || outgoing.writableEnded || outgoing.headersSent) {
if (outgoing.destroyed || outgoing.writableEnded) {
console.info('The response is already finished.')
return
}

if (outgoing.headersSent) {
outgoing.destroy()
console.info('The response has already been sent.')
return
}

// now we can write the response headers and status
outgoing.writeHead(res.status, resHeaderRecord)

Expand Down

0 comments on commit 72cdce6

Please sign in to comment.