Closed as not planned
Description
Symfony version(s) affected
7.1.*
Description
When we use symfony/symfony
and configure the error_controller
in the config/packages/framework.yaml
file, when we get the request_method
, there is an specific case where the request_method
it's always GET
.
How to reproduce
- Create a new symfony project
- Configure an
error_controller
in theconfig/packages/framework.yaml
file - Create a new controller with a POST endpoint that throws a BadRequestHttpException
- Make a POST request to the endpoint
- Check the
request_method
in theerror_controller
- The
request_method
is set toGET
when it should bePOST
in$request->getMethod()
Possible Solution
Change method Symfony\Component\HttpKernel\EventListener::duplicateRequest
lines:
$attributes = [
'_controller' => $this->controller,
'exception' => $exception,
'logger' => DebugLoggerConfigurator::getDebugLogger($this->logger),
];
$request = $request->duplicate(null, null, $attributes);
$request->setMethod('GET');
return $request;
to
$attributes = [
'_controller' => $this->controller,
'exception' => $exception,
'logger' => DebugLoggerConfigurator::getDebugLogger($this->logger),
];
$originalRequestmethod = $request->getMethod();
$request = $request->duplicate(null, null, $attributes);
$request->setMethod($originalRequestmethod);
return $request;
That is a quick fix, maybe what needs to be done, is make the $request->duplicate
method more clear, as it seems it's not really duplicating. Or at least not set a hardcoded GET
.
Additional Context
Please check this repository where we reproduce the bug and can be seen in the tests: