Skip to content
Closed
Show file tree
Hide file tree
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
End readable side of the stream on trailers or bodyless requests
  • Loading branch information
apapirovski committed Sep 5, 2017
commit 85f9ab01a46016edce900b388533a46830d63510
2 changes: 0 additions & 2 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ function onStreamTrailers(trailers, flags, rawTrailers) {
const request = this[kRequest];
Object.assign(request[kTrailers], trailers);
request[kRawTrailers].push(...rawTrailers);
// also causes the request stream to end
request.push(null);
}

function onStreamEnd() {
Expand Down
3 changes: 3 additions & 0 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ function onSessionHeaders(id, cat, flags, headers) {
debug(`[${sessionName(owner[kType])}] emitting stream '${event}' event`);
process.nextTick(emit.bind(stream, event, obj, flags, headers));
}
if (endOfStream) {
stream.push(null);
}
}

// Called to determine if there are trailers to be sent at the end of a
Expand Down
40 changes: 40 additions & 0 deletions test/parallel/test-http2-compat-serverrequest-end.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Flags: --expose-http2
'use strict';

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const h2 = require('http2');

// Http2ServerRequest should always end readable stream
// even on GET requests with no body

const server = h2.createServer();
server.listen(0, common.mustCall(function() {
const port = server.address().port;
server.once('request', common.mustCall(function(request, response) {
request.on('data', () => {});
request.on('end', common.mustCall(() => {
response.on('finish', common.mustCall(function() {
server.close();
}));
response.end();
}));
}));

const url = `http://localhost:${port}`;
const client = h2.connect(url, common.mustCall(function() {
const headers = {
':path': '/foobar',
':method': 'GET',
':scheme': 'http',
':authority': `localhost:${port}`
};
const request = client.request(headers);
request.resume();
request.on('end', common.mustCall(function() {
client.destroy();
}));
request.end();
}));
}));