};
ctx = {};
});
- it('collects body without writing', function () {
+ it('collects response without writing', function () {
Dingus.setHeadHandler(req, res, ctx);
res.write(Buffer.from('foo'));
res.write('baz');
res.end('quux');
assert(!origWrite.called);
assert(origEnd.called);
+ assert.deepStrictEqual(ctx.responseBody, undefined);
+ });
+ it('collects response without writing, persists written data', function () {
+ Dingus.setHeadHandler(req, res, ctx, true);
+ res.write(Buffer.from('foo'));
+ res.write('baz');
+ res.write();
+ res.end('quux');
+ assert(!origWrite.called);
+ assert(origEnd.called);
assert.deepStrictEqual(ctx.responseBody, Buffer.from('foobazquux'));
});
it('ignores non-head method', function () {
assert.strictEqual(e, 'foo');
}
});
+ it('limits size', async function () {
+ const p = dingus.bodyData(res, 8);
+ resEvents['data'](Buffer.from('foobar'));
+ resEvents['data'](Buffer.from('bazquux'));
+ try {
+ await p;
+ assert.fail(noExpectedException);
+ } catch (e) {
+ assert.strictEqual(e.statusCode, 413);
+ }
+ });
}); // bodyData
describe('ingestBody', function () {