diff --git a/lib/_http_server.js b/lib/_http_server.js index 496ebf285c814e..c78d7a8ac6de6c 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -363,6 +363,7 @@ function connectionListenerInternal(server, socket) { // Override on to unconsume on `data`, `readable` listeners socket.on = socketOnWrap; + socket.setEncoding = socketSetEncoding; // We only consume the socket if it has never been consumed before. if (socket._handle) { @@ -379,7 +380,6 @@ function connectionListenerInternal(server, socket) { socket._paused = false; } - function updateOutgoingData(socket, state, delta) { state.outgoingData += delta; if (socket._paused && @@ -454,7 +454,6 @@ function socketOnEnd(server, socket, parser, state) { function socketOnData(server, socket, parser, state, d) { assert(!socket._paused); debug('SERVER socketOnData %d', d.length); - var ret = parser.execute(d); onParserExecuteCommon(server, socket, parser, state, ret, d); } @@ -663,6 +662,10 @@ function onSocketPause() { } } +function socketSetEncoding() { + throw new errors.Error('ERR_METHOD_NOT_IMPLEMENTED', 'setEncoding'); +} + function unconsume(parser, socket) { if (socket._handle) { if (parser._consumed) diff --git a/test/parallel/test-http-socket-encoding-error.js b/test/parallel/test-http-socket-encoding-error.js new file mode 100644 index 00000000000000..cfb96f4f81bc2e --- /dev/null +++ b/test/parallel/test-http-socket-encoding-error.js @@ -0,0 +1,23 @@ +'use strict'; + +const common = require('../common'); +const http = require('http'); + +const server = http.createServer().listen(0, connectToServer); + +server.on('connection', (socket) => { + common.expectsError(() => socket.setEncoding(''), + { + code: 'ERR_METHOD_NOT_IMPLEMENTED', + type: Error + }); + + socket.end(); +}); + +function connectToServer() { + const client = new http.Agent().createConnection(this.address().port, () => { + client.end(); + }) + .on('end', () => server.close()); +}