Skip to content

Original body removed when parsedBody is provided #390

Description

@mcustiel

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&param2=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?

Activity

  1. WyriHaximus commented on Aug 31, 2020

    @WyriHaximus
    Member

    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

  2. mcustiel commented on Aug 31, 2020

    @mcustiel
    Author

    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.

  3. WyriHaximus commented on Sep 12, 2020

    @WyriHaximus
    Member

    @mcustiel Ah ok I get it now.

    Hey @clue what do you think about a marker middleware like StreamingRequestMiddleware but 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 .)

  4. clue commented on Sep 16, 2020

    @clue
    Member

    @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.

  5. clue commented on Sep 17, 2020

    @clue
    Member

    Closed via #395 :shipit:

  6. mcustiel commented on Sep 17, 2020

    @mcustiel
    Author

    Thank you for fixing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions