1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5const http = require('http'); 6 7const server = http.createServer().listen(0, connectToServer); 8 9server.on('connection', common.mustCall((socket) => { 10 assert.throws( 11 () => { 12 socket.setEncoding(''); 13 }, 14 { 15 code: 'ERR_HTTP_SOCKET_ENCODING', 16 name: 'Error', 17 message: 'Changing the socket encoding is not ' + 18 'allowed per RFC7230 Section 3.' 19 } 20 ); 21 22 socket.end(); 23})); 24 25function connectToServer() { 26 const client = new http.Agent().createConnection(this.address().port, () => { 27 client.end(); 28 }).on('end', () => server.close()); 29} 30