diff options
author | James M Snell <jasnell@gmail.com> | 2017-07-31 14:10:24 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-08-04 12:57:13 -0700 |
commit | b484ea1fabdbcf965d471dc8ef3dc64564e798e4 (patch) | |
tree | 7a7b27d86eb4de02a181e6ac9a5112c9cc891ad1 /test/parallel/test-http2-trailers.js | |
parent | 59e509808aeb85e33a16756764f2b496d5b8fcdd (diff) | |
download | android-node-v8-b484ea1fabdbcf965d471dc8ef3dc64564e798e4.tar.gz android-node-v8-b484ea1fabdbcf965d471dc8ef3dc64564e798e4.tar.bz2 android-node-v8-b484ea1fabdbcf965d471dc8ef3dc64564e798e4.zip |
http2: refactor trailers API
Rather than using the `'fetchTrailers'` event to collect trailers,
a new `getTrailers` callback option is supported. If not set, the
internals will skip calling out for trailers at all. Expands the
test to make sure trailers work from the client side also.
PR-URL: https://github.com/nodejs/node/pull/14239
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/parallel/test-http2-trailers.js')
-rw-r--r-- | test/parallel/test-http2-trailers.js | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/test/parallel/test-http2-trailers.js b/test/parallel/test-http2-trailers.js index 04ad3b0ff9..ed2d4b9e53 100644 --- a/test/parallel/test-http2-trailers.js +++ b/test/parallel/test-http2-trailers.js @@ -15,12 +15,16 @@ const server = h2.createServer(); server.on('stream', common.mustCall(onStream)); function onStream(stream, headers, flags) { + stream.on('trailers', common.mustCall((headers) => { + assert.strictEqual(headers[trailerKey], trailerValue); + })); stream.respond({ 'content-type': 'text/html', ':status': 200 - }); - stream.on('fetchTrailers', function(trailers) { - trailers[trailerKey] = trailerValue; + }, { + getTrailers: common.mustCall((trailers) => { + trailers[trailerKey] = trailerValue; + }) }); stream.end(body); } @@ -29,16 +33,19 @@ server.listen(0); server.on('listening', common.mustCall(function() { const client = h2.connect(`http://localhost:${this.address().port}`); - const req = client.request({ ':path': '/' }); + const req = client.request({ ':path': '/', ':method': 'POST' }, { + getTrailers: common.mustCall((trailers) => { + trailers[trailerKey] = trailerValue; + }) + }); req.on('data', common.mustCall()); req.on('trailers', common.mustCall((headers) => { assert.strictEqual(headers[trailerKey], trailerValue); - req.end(); })); req.on('end', common.mustCall(() => { server.close(); client.destroy(); })); - req.end(); + req.end('data'); })); |