Skip to content

[Http-Foundation] Empty request data when using application/x-www-form-urlencoded content type #62643

@mcop1

Description

@mcop1

Symfony version(s) affected

7.4.0

Description

When sending an HTTP request with method DELETE and content type application/x-www-form-urlencoded to one of our endpoints (payload example: id=1234), the request body is not available in the controller.
This also occurs with other HTTP methods.

It appears that the body is parsed twice during the runtime initialization process, first parse reads the data and clears the input stream, second parse returns empty arrays then.

First parse (body still present)

  • SymfonyRuntime::getArgument()
  • calls Request::createFromGlobals()
  • calls request_parse_body

Second parse (body cleared)

  • SymfonyRuntime::getRunner()
  • calls Request::createFromGlobals()
  • calls request_parse_body again

request_parse_body cannot be called twice, therefore the body is empty afterwards.

The commit that introduced request_parse_body:
symfony/http-foundation@f9b8417

SymfonyRuntime::getArgument() & SymfonyRuntime::getRunner()
https://github.com/symfony/runtime/blob/7.4/SymfonyRuntime.php#L220
https://github.com/symfony/runtime/blob/7.4/SymfonyRuntime.php#L175

How to reproduce

Send http request including DELETE method, content type application/x-www-form-urlencoded and form data to an endpoint.

Possible Solution

No response

Additional Context

PHP 8.4

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