-
-
Notifications
You must be signed in to change notification settings - Fork 755
Description
Looking at:
Line 62 in 59c3615
| req.body = req.body || {} |
It seems that when the body is actually null/empty (as with a GET), bodyParser.text will set {} as the body. This can be confusing to later handlers. It seems to me that it should either be left null or set to the empty string.
Background on my use case: I'm implementing a proxy that transforms the request based on the user's authorization. There may or may not be a request body, but if there is, I may need to transform it and then restream it. So my request handling looks like:
app.use(bodyParser.text({'type': '*/*'}), authorizationHandler, reqJsonRestreamer)
If it's a GET request and there is no actual body, bodyParser still sets one, authorizationHandler doesn't know whether there was a real body or not, and when reqJsonRestreamer runs against {} it tries to stream a request body where there was none originally, and the request hangs.
The workaround is to have the next handler check if the body is an object or string treat the object as an empty body. But it shouldn't be necessary if bodyParser just set body accurately in this case.