Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: setEncoding error for incoming packets #18178

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -379,7 +380,6 @@ function connectionListenerInternal(server, socket) {
socket._paused = false;
}


function updateOutgoingData(socket, state, delta) {
state.outgoingData += delta;
if (socket._paused &&
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-http-socket-encoding-error.js
Original file line number Diff line number Diff line change
@@ -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) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to have a common.mustCall around the callback as the assertion happens in it.

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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking nit: this looks a bit off. I would just move it to the line above.

}