Skip to content

Commit

Permalink
fix: do not auto destroy request stream (#132)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

Co-authored-by: devin ivy <[email protected]>
  • Loading branch information
achingbrain and devinivy authored Sep 2, 2020
1 parent e84429e commit d7080c8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down

0 comments on commit d7080c8

Please sign in to comment.