Skip to content

Commit a5fa2c6

Browse files
committed
refactor: remove setting req.body to undefined
Reasoning: the various parsers should not modify the request object until it is clear it should be applied. Setting a property, even to undefined, may affect assumptions elsewhere. For example, `'req' in body` would be truthy even if the rest of the middleware was not applied. It can be removed entirely since all tests are still passing without it. However, I recognize that some third-party consumers may still need it to be set. In either case, the current version is not compatible with, for example, tRPC v11 when using FormData. So without this change, the workaround is to add a condition to avoid applying the middleware at all. Example: ```js const json = express.json(); app.use((req, res, next) => { if (req.url.includes('trpc')) return next(); return json(req, res, next); }); ```
1 parent 1fd3222 commit a5fa2c6

File tree

1 file changed

+0
-4
lines changed

1 file changed

+0
-4
lines changed

lib/read.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ function read (req, res, next, parse, debug, options) {
4444
return
4545
}
4646

47-
if (!('body' in req)) {
48-
req.body = undefined
49-
}
50-
5147
// skip requests without bodies
5248
if (!hasBody(req)) {
5349
debug('skip empty body')

0 commit comments

Comments
 (0)