hono
hono copied to clipboard
feat: introduce Body Limit Middleware using stream
This is an implementation of the feature proposed in #2077 using stream.
How to use
Simply specify the maximum size.
app.post(
'/hello',
bodyLimit({
maxSize: 15 * Unit.b, // byte,
onError: (c) => {
return c.text('oveflow :(', 413)
},
}),
(c) => {
return c.text('pass :)')
}
)
Using stream
The problem discussed in #2077 that a body must be read at a time is solved by using stream.
c.req.bodyCache
It uses c.req.bodyCache used by the Validator implementation. By setting the loaded ArrayBuffer to c.req.bodyCache.arrayBuffer, such as c.req.json() will use that cached body from then on.
Author should do the followings, if applicable
- [x] Add tests
- [x] Run tests
- [x]
yarn denoifyto generate files for Deno