forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: support non-empty DATA frame with END_STREAM flag
Adds support for reading from a stream where the final frame is a non-empty DATA frame with the END_STREAM flag set, instead of hanging waiting for another frame. Fixes: nodejs#31309 Refs: https://nghttp2.org/documentation/types.html#c.nghttp2_on_data_chunk_recv_callback PR-URL: nodejs#33875 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
7e85d4a
commit 2a3914d
Showing
3 changed files
with
111 additions
and
23 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const assert = require('assert'); | ||
const http2 = require('http2'); | ||
|
||
const { PerformanceObserver } = require('perf_hooks'); | ||
|
||
const server = http2.createServer(); | ||
|
||
server.on('stream', (stream, headers) => { | ||
stream.respond({ | ||
'content-type': 'text/html', | ||
':status': 200 | ||
}); | ||
switch (headers[':path']) { | ||
case '/singleEnd': | ||
stream.end('OK'); | ||
// Backport v10.x: Manually pack END_STREAM flag | ||
stream._final(() => {}); | ||
break; | ||
case '/sequentialEnd': | ||
stream.write('OK'); | ||
stream.end(); | ||
// Backport v10.x: Manually pack END_STREAM flag | ||
stream._final(() => {}); | ||
break; | ||
case '/delayedEnd': | ||
stream.write('OK', () => stream.end()); | ||
break; | ||
} | ||
}); | ||
|
||
function testRequest(path, targetFrameCount, callback) { | ||
const obs = new PerformanceObserver((list, observer) => { | ||
const entry = list.getEntries()[0]; | ||
if (entry.name !== 'Http2Session') return; | ||
if (entry.type !== 'client') return; | ||
assert.strictEqual(entry.framesReceived, targetFrameCount); | ||
observer.disconnect(); | ||
callback(); | ||
}); | ||
obs.observe({ entryTypes: ['http2'] }); | ||
const client = http2.connect(`http://localhost:${server.address().port}`, () => { | ||
const req = client.request({ ':path': path }); | ||
req.resume(); | ||
req.end(); | ||
req.on('end', () => client.close()); | ||
}); | ||
} | ||
|
||
// SETTINGS => SETTINGS => HEADERS => DATA | ||
const MIN_FRAME_COUNT = 4; | ||
|
||
server.listen(0, () => { | ||
testRequest('/singleEnd', MIN_FRAME_COUNT, () => { | ||
testRequest('/sequentialEnd', MIN_FRAME_COUNT, () => { | ||
testRequest('/delayedEnd', MIN_FRAME_COUNT + 1, () => { | ||
server.close(); | ||
}); | ||
}); | ||
}); | ||
}); |