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
{{ message }}
Repository navigation
Original body removed when parsedBody is provided #390
Hello.
I noticed this behavior:
I send this request to ReactPHP: curl -X POST -H "Content-Type: application/json" -d '{"param1":"value1","param2":"value2"}' http://localhost:8086/test
Because application/json body is not parsed, I can access the raw body through $request->getBody() without any problem. If I call $request->getParsedBody() it will return null.
Then I send this request, were the content type is application/x-www-form-urlencoded: curl --data "param1=value1¶m2=value2" http://localhost:8086/test
The body will be parsed and I can access the variables through $request->getParsedBody(), but if I try to access the raw body I can't do it.
My application (https://github.com/mcustiel/phiremock) relies on having access to the raw body to validate configurations provided by the client, could you please accept to access the raw request body even though it's parseable?
Hello @WyriHaximus
I see now that my explanation was a bit confusing.
My issue is as following:
If I send a request with an unparseable body (json or plain text), I can access it on the server side using $request->getBody(). That's correct.
But if I send a request with a parseable body (for instance with Content-Type: application/x-www-form-urlencoded) then I can't access the raw request body through $request->getBody(), it will be an empty string. I can only access it through the getParsedBody method.
I agree that clearing the request body for some requests is somewhat inconsistent, so I've just filed #395 to make sure you can always read the raw request body.
Activity
WyriHaximus commentedon Aug 31, 2020
Hey @mcustiel we only included support for direct HTTP related body types. Have a look at https://github.com/WyriHaximus/reactphp-http-middleware-custom-request-body-parsers for JSON parsing
mcustiel commentedon Aug 31, 2020
Hello @WyriHaximus
I see now that my explanation was a bit confusing.
My issue is as following:
If I send a request with an unparseable body (json or plain text), I can access it on the server side using
$request->getBody(). That's correct.But if I send a request with a parseable body (for instance with
Content-Type: application/x-www-form-urlencoded) then I can't access the raw request body through$request->getBody(), it will be an empty string. I can only access it through thegetParsedBodymethod.WyriHaximus commentedon Sep 12, 2020
@mcustiel Ah ok I get it now.
Hey @clue what do you think about a marker middleware like
StreamingRequestMiddlewarebut that one for not parsing the raw request body? (Note @mcustiel that this would mean no parsing for everything, if you still want to parse certain routes, have a look at https://github.com/WyriHaximus/reactphp-http-contextual-middleware-runner .)clue commentedon Sep 16, 2020
@mcustiel Thanks for bringing this up!
I agree that clearing the request body for some requests is somewhat inconsistent, so I've just filed #395 to make sure you can always read the raw request body.
clue commentedon Sep 17, 2020
Closed via #395
mcustiel commentedon Sep 17, 2020
Thank you for fixing this.