From 237aa7e9ae850bbaf39563b368bc617468f2136d Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 11 Apr 2018 16:11:35 -0700 Subject: http2: refactor how trailers are done Rather than an option, introduce a method and an event... ```js server.on('stream', (stream) => { stream.respond(undefined, { waitForTrailers: true }); stream.on('wantTrailers', () => { stream.sendTrailers({ abc: 'xyz'}); }); stream.end('hello world'); }); ``` This is a breaking change in the API such that the prior `options.getTrailers` is no longer supported at all. Ordinarily this would be semver-major and require a deprecation but the http2 stuff is still experimental. PR-URL: https://github.com/nodejs/node/pull/19959 Reviewed-By: Yuta Hiroto Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina --- ...-http2-compat-serverresponse-createpushresponse.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'test/parallel/test-http2-compat-serverresponse-createpushresponse.js') diff --git a/test/parallel/test-http2-compat-serverresponse-createpushresponse.js b/test/parallel/test-http2-compat-serverresponse-createpushresponse.js index e0ce51bfc7..1992d41af6 100644 --- a/test/parallel/test-http2-compat-serverresponse-createpushresponse.js +++ b/test/parallel/test-http2-compat-serverresponse-createpushresponse.js @@ -28,6 +28,15 @@ const server = h2.createServer((request, response) => { } ); + response.stream.on('close', () => { + response.createPushResponse({ + ':path': '/pushed', + ':method': 'GET' + }, common.mustCall((error) => { + assert.strictEqual(error.code, 'ERR_HTTP2_INVALID_STREAM'); + })); + }); + response.createPushResponse({ ':path': '/pushed', ':method': 'GET' @@ -36,16 +45,6 @@ const server = h2.createServer((request, response) => { assert.strictEqual(push.stream.id % 2, 0); push.end(pushExpect); response.end(); - - // wait for a tick, so the stream is actually closed - setImmediate(function() { - response.createPushResponse({ - ':path': '/pushed', - ':method': 'GET' - }, common.mustCall((error) => { - assert.strictEqual(error.code, 'ERR_HTTP2_INVALID_STREAM'); - })); - }); })); }); -- cgit v1.2.3