Skip to content

Commit

Permalink
docs, errors, http: disallow setEncoding on incoming packets
Browse files Browse the repository at this point in the history
added ERR_HTTP_INCOMING_SOCKET_ENCODING error and error docs
throw ERR_HTTP_INCOMING_SOCKET_ENCODING error when incoming request
socket encoding is manipulated

error report detailed in nodejs#18118

Fixes: nodejs#18118
Ref: nodejs#18178
  • Loading branch information
iSkore committed Apr 3, 2018
1 parent 345ff3c commit 4643c63
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,12 @@ An invalid symlink type was passed to the [`fs.symlink()`][] or

An attempt was made to add more headers after the headers had already been sent.

<a id="ERR_HTTP_INCOMING_SOCKET_ENCODING"></a>
### ERR_HTTP_INCOMING_SOCKET_ENCODING

An attempt was made to manipulate the encoding of an incoming request packet.
This is not allowed (RFC2616).

<a id="ERR_HTTP_INVALID_HEADER_VALUE"></a>
### ERR_HTTP_INVALID_HEADER_VALUE

Expand Down
2 changes: 1 addition & 1 deletion lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ function onSocketPause() {
}

function socketSetEncoding() {
throw new errors.Error('ERR_METHOD_NOT_IMPLEMENTED', 'setEncoding');
throw new errors.Error('ERR_HTTP_INCOMING_SOCKET_ENCODING', 'setEncoding');
}

function unconsume(parser, socket) {
Expand Down
3 changes: 3 additions & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,9 @@ E('ERR_HTTP2_STREAM_SELF_DEPENDENCY',
E('ERR_HTTP2_UNSUPPORTED_PROTOCOL', 'protocol "%s" is unsupported.', Error);
E('ERR_HTTP_HEADERS_SENT',
'Cannot %s headers after they are sent to the client', Error);
E('ERR_HTTP_INCOMING_SOCKET_ENCODING',
'Incoming socket encoding is not allowed (RFC 2616)',
Error);
E('ERR_HTTP_INVALID_HEADER_VALUE',
'Invalid value "%s" for header "%s"', TypeError);
E('ERR_HTTP_INVALID_STATUS_CODE', 'Invalid status code: %s', RangeError);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-socket-encoding-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const server = http.createServer().listen(0, connectToServer);
server.on('connection', (socket) => {
common.expectsError(() => socket.setEncoding(''),
{
code: 'ERR_METHOD_NOT_IMPLEMENTED',
code: 'ERR_HTTP_INCOMING_SOCKET_ENCODING',
type: Error
});

Expand Down

0 comments on commit 4643c63

Please sign in to comment.