fix: close socket when client error handled (#9816)

This commit is contained in:
刘巍峰 2022-08-25 02:16:46 +08:00 committed by GitHub
parent 05b3ce6aa7
commit ba62be40b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -190,7 +190,9 @@ 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. ' +
@ -198,5 +200,9 @@ export function setClientErrorHandler(
)
)
}
if ((err as any).code === 'ECONNRESET' || !socket.writable) {
return
}
socket.end(`HTTP/1.1 ${msg}\r\n\r\n`)
})
}