Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,11 @@ class Http2Stream extends Duplex {
if (!this.headersSent)
this[kProceed]();

if (!data.length) {
cb();
return;
}

const handle = this[kHandle];
const req = new WriteWrap();
req.stream = this[kID];
Expand Down Expand Up @@ -1659,6 +1664,11 @@ class Http2Stream extends Duplex {
if (!this.headersSent)
this[kProceed]();

if (!data.length) {
cb();
return;
}

const handle = this[kHandle];
const req = new WriteWrap();
req.stream = this[kID];
Expand Down
48 changes: 48 additions & 0 deletions test/parallel/test-http2-client-write-empty-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

const assert = require('assert');
const http2 = require('http2');

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

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

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