| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent add1fcd commit 790864b
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -958,6 +958,17 @@ added: v8.4.0 | |||
| 958 | 958 | Set to `true` if the `Http2Stream` instance has been destroyed and is no longer | |
| 959 | 959 | usable. | |
| 960 | 960 | ||
| 961 | + #### http2stream.endAfterHeaders | ||
| 962 | + <!-- YAML | ||
| 963 | + added: REPLACEME | ||
| 964 | + --> | ||
| 965 | + | ||
| 966 | + * {boolean} | ||
| 967 | + | ||
| 968 | + Set the `true` if the `END_STREAM` flag was set in the request or response | ||
| 969 | + HEADERS frame received, indicating that no additional data should be received | ||
| 970 | + and the readable side of the `Http2Stream` will be closed. | ||
| 971 | + | ||
| 961 | 972 | #### http2stream.pending | |
| 962 | 973 | <!-- YAML | |
| 963 | 974 | added: v9.4.0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -276,6 +276,8 @@ function onSessionHeaders(handle, id, cat, flags, headers) { | |||
| 276 | 276 | } else { | |
| 277 | 277 | stream = new ClientHttp2Stream(session, handle, id, opts); | |
| 278 | 278 | } | |
| 279 | + if (endOfStream) | ||
| 280 | + stream[kState].endAfterHeaders = true; | ||
| 279 | 281 | process.nextTick(emit, session, 'stream', stream, obj, flags, headers); | |
| 280 | 282 | } else { | |
| 281 | 283 | let event; | |
@@ -1548,7 +1550,8 @@ class Http2Stream extends Duplex { | |||
| 1548 | 1550 | flags: STREAM_FLAGS_PENDING, | |
| 1549 | 1551 | rstCode: NGHTTP2_NO_ERROR, | |
| 1550 | 1552 | writeQueueSize: 0, | |
| 1551 | - trailersReady: false | ||
| 1553 | + trailersReady: false, | ||
| 1554 | + endAfterHeaders: false | ||
| 1552 | 1555 | }; | |
| 1553 | 1556 | ||
| 1554 | 1557 | this.on('pause', streamOnPause); | |
@@ -1594,6 +1597,10 @@ class Http2Stream extends Duplex { | |||
| 1594 | 1597 | return `Http2Stream ${util.format(obj)}`; | |
| 1595 | 1598 | } | |
| 1596 | 1599 | ||
| 1600 | + get endAfterHeaders() { | ||
| 1601 | + return this[kState].endAfterHeaders; | ||
| 1602 | + } | ||
| 1603 | + | ||
| 1597 | 1604 | get sentHeaders() { | |
| 1598 | 1605 | return this[kSentHeaders]; | |
| 1599 | 1606 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,50 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + if (!common.hasCrypto) | ||
| 5 | + common.skip('missing crypto'); | ||
| 6 | + const assert = require('assert'); | ||
| 7 | + const http2 = require('http2'); | ||
| 8 | + const Countdown = require('../common/countdown'); | ||
| 9 | + | ||
| 10 | + const server = http2.createServer(); | ||
| 11 | + server.on('stream', common.mustCall((stream, headers) => { | ||
| 12 | + const check = headers[':method'] === 'GET' ? true : false; | ||
| 13 | + assert.strictEqual(stream.endAfterHeaders, check); | ||
| 14 | + stream.on('data', common.mustNotCall()); | ||
| 15 | + stream.on('end', common.mustCall()); | ||
| 16 | + stream.respond(); | ||
| 17 | + stream.end('ok'); | ||
| 18 | + }, 2)); | ||
| 19 | + | ||
| 20 | + const countdown = new Countdown(2, () => server.close()); | ||
| 21 | + | ||
| 22 | + server.listen(0, common.mustCall(() => { | ||
| 23 | + { | ||
| 24 | + const client = http2.connect(`http://localhost:${server.address().port}`); | ||
| 25 | + const req = client.request(); | ||
| 26 | + | ||
| 27 | + req.resume(); | ||
| 28 | + req.on('response', common.mustCall(() => { | ||
| 29 | + assert.strictEqual(req.endAfterHeaders, false); | ||
| 30 | + })); | ||
| 31 | + req.on('end', common.mustCall(() => { | ||
| 32 | + client.close(); | ||
| 33 | + countdown.dec(); | ||
| 34 | + })); | ||
| 35 | + } | ||
| 36 | + { | ||
| 37 | + const client = http2.connect(`http://localhost:${server.address().port}`); | ||
| 38 | + const req = client.request({ ':method': 'POST' }); | ||
| 39 | + | ||
| 40 | + req.resume(); | ||
| 41 | + req.end(); | ||
| 42 | + req.on('response', common.mustCall(() => { | ||
| 43 | + assert.strictEqual(req.endAfterHeaders, false); | ||
| 44 | + })); | ||
| 45 | + req.on('end', common.mustCall(() => { | ||
| 46 | + client.close(); | ||
| 47 | + countdown.dec(); | ||
| 48 | + })); | ||
| 49 | + } | ||
| 50 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments