Skip to content

Commit 4643c63

Browse files
committed
docs, errors, http: disallow setEncoding on incoming packets
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
1 parent 345ff3c commit 4643c63

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

doc/api/errors.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,12 @@ An invalid symlink type was passed to the [`fs.symlink()`][] or
794794

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

797+
<a id="ERR_HTTP_INCOMING_SOCKET_ENCODING"></a>
798+
### ERR_HTTP_INCOMING_SOCKET_ENCODING
799+
800+
An attempt was made to manipulate the encoding of an incoming request packet.
801+
This is not allowed (RFC2616).
802+
797803
<a id="ERR_HTTP_INVALID_HEADER_VALUE"></a>
798804
### ERR_HTTP_INVALID_HEADER_VALUE
799805

lib/_http_server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ function onSocketPause() {
685685
}
686686

687687
function socketSetEncoding() {
688-
throw new errors.Error('ERR_METHOD_NOT_IMPLEMENTED', 'setEncoding');
688+
throw new errors.Error('ERR_HTTP_INCOMING_SOCKET_ENCODING', 'setEncoding');
689689
}
690690

691691
function unconsume(parser, socket) {

lib/internal/errors.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,9 @@ E('ERR_HTTP2_STREAM_SELF_DEPENDENCY',
762762
E('ERR_HTTP2_UNSUPPORTED_PROTOCOL', 'protocol "%s" is unsupported.', Error);
763763
E('ERR_HTTP_HEADERS_SENT',
764764
'Cannot %s headers after they are sent to the client', Error);
765+
E('ERR_HTTP_INCOMING_SOCKET_ENCODING',
766+
'Incoming socket encoding is not allowed (RFC 2616)',
767+
Error);
765768
E('ERR_HTTP_INVALID_HEADER_VALUE',
766769
'Invalid value "%s" for header "%s"', TypeError);
767770
E('ERR_HTTP_INVALID_STATUS_CODE', 'Invalid status code: %s', RangeError);

test/parallel/test-http-socket-encoding-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const server = http.createServer().listen(0, connectToServer);
88
server.on('connection', (socket) => {
99
common.expectsError(() => socket.setEncoding(''),
1010
{
11-
code: 'ERR_METHOD_NOT_IMPLEMENTED',
11+
code: 'ERR_HTTP_INCOMING_SOCKET_ENCODING',
1212
type: Error
1313
});
1414

0 commit comments

Comments
 (0)