-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: use and 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. When writing to a stream, uses a END_STREAM flag on final DATA frame instead of adding an empty DATA frame. BREAKING: http2 client now expects servers to properly support END_STREAM flag Fixes: #31309 Fixes: #33891 Refs: https://nghttp2.org/documentation/types.html#c.nghttp2_on_data_chunk_recv_callback Backport-PR-URL: #34845 PR-URL: #33875 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
1 parent
b5bc280
commit 4d1df84
Showing
6 changed files
with
193 additions
and
47 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
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,61 @@ | ||
'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'); | ||
break; | ||
case '/sequentialEnd': | ||
stream.write('OK'); | ||
stream.end(); | ||
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(); | ||
}); | ||
}); | ||
}); | ||
}); |
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