forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs, errors, http, tests: 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. previously resulted in a fatal error Fixes: nodejs#18118 Ref: nodejs#18178 Ref: nodejs#19344
- 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()); | ||
} |