forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: nodejs#33405 Fixes: nodejs#18118 Refs: nodejs#18178 Refs: nodejs#19344 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
- Loading branch information
Showing
4 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} |