Skip to content

Commit 6657553

Browse files
committed
http: don't write error to socket
The state of the connection is unknown at this point and writing to it can corrupt client state before it is aware of an error.
1 parent 2c05bee commit 6657553

File tree

1 file changed

+0
-13
lines changed

1 file changed

+0
-13
lines changed

lib/_http_server.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -604,25 +604,12 @@ function onParserTimeout(server, socket) {
604604
}
605605

606606
const noop = () => {};
607-
const badRequestResponse = Buffer.from(
608-
`HTTP/1.1 400 ${STATUS_CODES[400]}${CRLF}` +
609-
`Connection: close${CRLF}${CRLF}`, 'ascii'
610-
);
611-
const requestHeaderFieldsTooLargeResponse = Buffer.from(
612-
`HTTP/1.1 431 ${STATUS_CODES[431]}${CRLF}` +
613-
`Connection: close${CRLF}${CRLF}`, 'ascii'
614-
);
615607
function socketOnError(e) {
616608
// Ignore further errors
617609
this.removeListener('error', socketOnError);
618610
this.on('error', noop);
619611

620612
if (!this.server.emit('clientError', e, this)) {
621-
if (this.writable) {
622-
const response = e.code === 'HPE_HEADER_OVERFLOW' ?
623-
requestHeaderFieldsTooLargeResponse : badRequestResponse;
624-
this.write(response);
625-
}
626613
this.destroy(e);
627614
}
628615
}

0 commit comments

Comments
 (0)