Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2: fix endless loop when writing empty string #18924

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[squash] extend test case
  • Loading branch information
addaleax committed Feb 22, 2018
commit b702ba350ff4ea43b1894ae436bc67d216040908
78 changes: 42 additions & 36 deletions test/parallel/test-http2-client-write-empty-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,48 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

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}"`);
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');
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();
}));

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();
}));

req.write('');
req.end();
}));
}