Skip to content

Commit

Permalink
fix(http): use parsed body instead of attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreGerault committed Jul 13, 2021
1 parent 180bc8e commit 7bc7715
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/AGerault/HTTP/Middlewares/HttpMethodMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ class HttpMethodMiddleware implements MiddlewareInterface
{
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$method = $request->getAttribute('_method') ?? $request->getMethod();

if ($request->getAttribute('_method')) {
$request = $request->withMethod($method);
if (array_key_exists('_method', $request->getParsedBody())) {
$request = $request->withMethod($request->getParsedBody()['_method']);
}

return $handler->handle($request);
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/HTTP/HttpMethodMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

it('should change the request method', function () {
$request = new ServerRequest("POST", "/");
$request = $request->withAttribute("_method", "PUT");
$request = $request->withParsedBody(["_method" => "PUT"]);
$middleware = new HttpMethodMiddleware();
$handler = new DummyHandler();

Expand Down

0 comments on commit 7bc7715

Please sign in to comment.