summaryrefslogtreecommitdiff
path: root/lib/_http_server.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/_http_server.js')
-rw-r--r--lib/_http_server.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/_http_server.js b/lib/_http_server.js
index 458988fad8..a133c2c153 100644
--- a/lib/_http_server.js
+++ b/lib/_http_server.js
@@ -38,6 +38,7 @@ const {
const { OutgoingMessage } = require('_http_outgoing');
const { outHeadersKey, ondrain } = require('internal/http');
const errors = require('internal/errors');
+const Buffer = require('buffer').Buffer;
const STATUS_CODES = {
100: 'Continue',
@@ -451,13 +452,21 @@ function onParserExecute(server, socket, parser, state, ret, d) {
onParserExecuteCommon(server, socket, parser, state, ret, undefined);
}
+const badRequestResponse = Buffer.from(
+ 'HTTP/1.1 400 ' + STATUS_CODES[400] + CRLF + CRLF, 'ascii'
+);
function socketOnError(e) {
// Ignore further errors
this.removeListener('error', socketOnError);
this.on('error', () => {});
- if (!this.server.emit('clientError', e, this))
+ if (!this.server.emit('clientError', e, this)) {
+ if (this.writable) {
+ this.end(badRequestResponse);
+ return;
+ }
this.destroy(e);
+ }
}
function onParserExecuteCommon(server, socket, parser, state, ret, d) {