mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00
http: fixed socket.setEncoding fatal error
Applied updates from previous pull-requests to disallow socket.setEncoding before a http connection is parsed. Wrapped `socket.setEncoding` to throw an error. This previously resulted in a fatal error. PR-URL: https://github.com/nodejs/node/pull/33405 Fixes: https://github.com/nodejs/node/issues/18118 Refs: https://github.com/nodejs/node/pull/18178 Refs: https://github.com/nodejs/node/pull/19344 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
10596b601e
commit
32b641e528
4 changed files with 43 additions and 0 deletions
29
test/parallel/test-http-socket-encoding-error.js
Normal file
29
test/parallel/test-http-socket-encoding-error.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const http = require('http');
|
||||
|
||||
const server = http.createServer().listen(0, connectToServer);
|
||||
|
||||
server.on('connection', common.mustCall((socket) => {
|
||||
assert.throws(
|
||||
() => {
|
||||
socket.setEncoding('');
|
||||
},
|
||||
{
|
||||
code: 'ERR_HTTP_SOCKET_ENCODING',
|
||||
name: 'Error',
|
||||
message: 'Changing the socket encoding is not ' +
|
||||
'allowed per RFC7230 Section 3.'
|
||||
}
|
||||
);
|
||||
|
||||
socket.end();
|
||||
}));
|
||||
|
||||
function connectToServer() {
|
||||
const client = new http.Agent().createConnection(this.address().port, () => {
|
||||
client.end();
|
||||
}).on('end', () => server.close());
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue