Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add check for closed requests (#162)
## Checklist - [x] I have ensured my pull request is not behind the main or master branch of the original repository. - [x] I have rebased all commits where necessary so that reviewing this pull request can be done without having to merge it first. - [x] I have written a commit message that passes commitlint linting. - [x] I have ensured that my code changes pass linting tests. - [x] I have ensured that my code changes pass unit tests. - [x] I have described my pull request and the reasons for code changes along with context if necessary. ## Changes Added a check for `req.ctx.closed` to ensure that, when a request is closed (canceled) before reaching the bodyparser middleware, the body of the closed request is not attempted to be parsed (which would result in an error). Instead, if the request is closed, then the middleware returns a `499 Client Closed Request` status. ## Reason Errors can occur when parsing bodies of closed requests - `stream not readable`. This indicates the request was cancelled. This can happen when body parser is not on the "synchronous path" of a request - e.g. if Auth is verified asynchronously from headers before bothering to parse the bodies. This allows time for users to occasionally close the request, resulting in a `500 'stream not readable'` error.
- Loading branch information