Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
http: don't write error to socket
The state of the connection is unknown at this point and writing to it can corrupt client state before it is aware of an error. PR-URL: #34465 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
with
34 additions
and 3 deletions.
- +2 −2 doc/api/http.md
- +1 −1 lib/_http_server.js
- +31 −0 test/parallel/test-http-header-badrequest.js
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
| @@ -0,0 +1,31 @@ | ||
| 'use strict'; | ||
| const { mustCall } = require('../common'); | ||
| const assert = require('assert'); | ||
| const { createServer } = require('http'); | ||
| const { createConnection } = require('net'); | ||
|
|
||
| const server = createServer(); | ||
|
|
||
| server.on('request', mustCall((req, res) => { | ||
| res.write('asd', () => { | ||
| res.socket.emit('error', new Error('kaboom')); | ||
| }); | ||
| })); | ||
|
|
||
| server.listen(0, mustCall(() => { | ||
| const c = createConnection(server.address().port); | ||
| let received = ''; | ||
|
|
||
| c.on('connect', mustCall(() => { | ||
| c.write('GET /blah HTTP/1.1\r\n\r\n'); | ||
| })); | ||
| c.on('data', mustCall((data) => { | ||
| received += data.toString(); | ||
| })); | ||
| c.on('end', mustCall(() => { | ||
| // Should not include anything else after asd. | ||
| assert.strictEqual(received.indexOf('asd\r\n'), received.length - 5); | ||
| c.end(); | ||
| })); | ||
| c.on('close', mustCall(() => server.close())); | ||
| })); |