mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Fix http socket encoding check (#20031)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
@@ -1408,6 +1408,12 @@ const NodeHTTPServerSocket = class Socket extends Duplex {
|
||||
return this;
|
||||
}
|
||||
|
||||
setEncoding(_encoding) {
|
||||
const err = new Error("Changing the socket encoding is not allowed per RFC7230 Section 3.");
|
||||
err.code = "ERR_HTTP_SOCKET_ENCODING";
|
||||
throw err;
|
||||
}
|
||||
|
||||
unref() {
|
||||
return this;
|
||||
}
|
||||
|
||||
26
test/js/node/parallel/test-http-socket-encoding-error.js
Normal file
26
test/js/node/parallel/test-http-socket-encoding-error.js
Normal file
@@ -0,0 +1,26 @@
|
||||
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());
|
||||
}
|
||||
Reference in New Issue
Block a user