From d7080c8756f660df2ddc08541855f44d1e4dabb1 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 2 Sep 2020 03:19:53 +0100 Subject: [PATCH] fix: do not auto destroy request stream (#132) * fix: do not override destroy method The node docs say: > Implementors should not override this method, but instead implement readable._destroy() Fixes hapijs/hapi#4149 * do not autodestroy request stream * restore destroy method * Revert changes in favor of #133, keeping new test Co-authored-by: Alex Potsides Co-authored-by: devin ivy --- test/index.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/index.js b/test/index.js index 3bd350d..835ab0f 100755 --- a/test/index.js +++ b/test/index.js @@ -493,6 +493,30 @@ describe('inject()', () => { const res = await Shot.inject(dispatch, { method: 'post', url: '/', payload: internals.getTestStream(), headers }); expect(res.payload).to.equal('100'); }); + + it('iterates over payload', async () => { + + const dispatch = async function (req, res) { + + let output = ''; + + for await (const chunk of req) { + output += chunk.toString(); + } + + res.writeHead(200, { 'Content-Length': output.length }); + res.end(output); + req.destroy(); + }; + + const body = Buffer.from('something special just for you'); + const res = await Shot.inject(dispatch, { + method: 'get', + url: '/', + payload: body + }); + expect(res.payload.toString()).to.equal(body.toString()); + }); }); describe('writeHead()', () => {