Skip to content

Commit

Permalink
fix: close socket when client error handled (#9816)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuweifeng authored Aug 24, 2022
1 parent 05b3ce6 commit ba62be4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/vite/src/node/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,19 @@ export function setClientErrorHandler(
logger: Logger
): void {
server.on('clientError', (err, socket) => {
let msg = '400 Bad Request'
if ((err as any).code === 'HPE_HEADER_OVERFLOW') {
msg = '431 Request Header Fields Too Large'
logger.warn(
colors.yellow(
'Server responded with status code 431. ' +
'See https://vitejs.dev/guide/troubleshooting.html#_431-request-header-fields-too-large.'
)
)
}
if ((err as any).code === 'ECONNRESET' || !socket.writable) {
return
}
socket.end(`HTTP/1.1 ${msg}\r\n\r\n`)
})
}

0 comments on commit ba62be4

Please sign in to comment.