-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: check endless loop while writing empty string
Refs: #18673 PR-URL: #18924 Refs: #18673 Refs: https://github.com/nodejs/node/blob/v9.5.0/src/node_http2.cc#L1481-L1484 Refs: https://github.com/nodejs/node/blob/v9.5.0/lib/_http_outgoing.js#L659-L661 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
- Loading branch information
Showing
1 changed file
with
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const http2 = require('http2'); | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
for (const chunkSequence of [ | ||
[ '' ], | ||
[ '', '' ] | ||
]) { | ||
const server = http2.createServer(); | ||
server.on('stream', common.mustCall((stream, headers, flags) => { | ||
stream.respond({ 'content-type': 'text/html' }); | ||
|
||
let data = ''; | ||
stream.on('data', common.mustNotCall((chunk) => { | ||
data += chunk.toString(); | ||
})); | ||
stream.on('end', common.mustCall(() => { | ||
stream.end(`"${data}"`); | ||
})); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const port = server.address().port; | ||
const client = http2.connect(`http://localhost:${port}`); | ||
|
||
const req = client.request({ | ||
':method': 'POST', | ||
':path': '/' | ||
}); | ||
|
||
req.on('response', common.mustCall((headers) => { | ||
assert.strictEqual(headers[':status'], 200); | ||
assert.strictEqual(headers['content-type'], 'text/html'); | ||
})); | ||
|
||
let data = ''; | ||
req.setEncoding('utf8'); | ||
req.on('data', common.mustCallAtLeast((d) => data += d)); | ||
req.on('end', common.mustCall(() => { | ||
assert.strictEqual(data, '""'); | ||
server.close(); | ||
client.close(); | ||
})); | ||
|
||
for (const chunk of chunkSequence) | ||
req.write(chunk); | ||
req.end(); | ||
})); | ||
} |