You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the body was not parsed by some other parser before bodyParser.json, and if the current request is NOT to be parsed with current parser, I expect the req.body to be undefined.
Current behaviour
The shouldParse check happens after the body has been populated with an empty object, thus polluting the req.
My usecase
Currently I am using express as a backend proxy for my react application.
The vast majority of my requests are fetch GET with missing content-type and with accept: */*. There are some user-profile requests (GET /user, for example, that expects json in return).
But two of my requests are very different. One is POST /save-something, which sends over content-type: application/json, and the other one is POST /upload-a-file-to-another-system with content-type: application/binary and content-transfer-encoding: binary.
The server serving as a proxy SHOULD NOT look into the request to understand how to parse/reparse it. So, my expected behaviour would be for all requests that were not parsed by JSON to leave the req.body = undefined, so that I can make a general check on req.is("json") or req.is("binary"), should I need some custom behaviour.
Example
I decided I could write up a simple script to illustrate the point, if you wish. Mostly it contains logs on the console :D
@dougwilson I saw mentions of the branch 2.0, but somehow it didn't cross my mind that it was the body-parser repo (whereas the express itself is v4 already 😆 ) ah well, my bad.
Problem
https://github.com/expressjs/body-parser/blob/master/lib/types/json.js#L99-L121
(seems to echo #146 ?)
Expected behaviour
If the body was not parsed by some other parser before
bodyParser.json
, and if the current request is NOT to be parsed with current parser, I expect thereq.body
to beundefined
.Current behaviour
The
shouldParse
check happens after the body has been populated with an empty object, thus polluting thereq
.My usecase
Currently I am using express as a backend proxy for my react application.
The vast majority of my requests are
fetch GET
with missingcontent-type
and withaccept: */*
. There are some user-profile requests (GET /user
, for example, that expects json in return).But two of my requests are very different. One is
POST /save-something
, which sends overcontent-type: application/json
, and the other one isPOST /upload-a-file-to-another-system
withcontent-type: application/binary
andcontent-transfer-encoding: binary
.The server serving as a proxy SHOULD NOT look into the request to understand how to parse/reparse it. So, my expected behaviour would be for all requests that were not parsed by JSON to leave the
req.body = undefined
, so that I can make a general check onreq.is("json")
orreq.is("binary")
, should I need some custom behaviour.Example
I decided I could write up a simple script to illustrate the point, if you wish. Mostly it contains logs on the console :D
package.json
index.js
Output
The text was updated successfully, but these errors were encountered: