Skip to content

Commit

Permalink
Include HTTP method DELETE to a body parsing list; parse arguments on…
Browse files Browse the repository at this point in the history
… HTTP calls from the Frontend
  • Loading branch information
roxblnfk committed Dec 17, 2023
1 parent ea323b3 commit c2c71f8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Info
{
public const NAME = 'Buggregator Trap';
public const VERSION = '1.3.0';
public const VERSION = '1.3.1';
public const LOGO_CLI_COLOR = <<<CONSOLE
\e[44;97;1m \e[0m
\e[44;97;1m ▄█▀ ▀█▄ \e[0m
Expand Down
18 changes: 15 additions & 3 deletions src/Sender/Frontend/Http/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,28 @@ public function handle(ServerRequestInterface $request, callable $next): Respons
{
try {
$path = \trim($request->getUri()->getPath(), '/');
$method = $request->getMethod();
$method = Method::fromString($request->getMethod());

$handler = $this->router->match(Method::fromString($method), $path);
$handler = $this->router->match($method, $path);

if ($handler === null) {
return new Response(404);
}

try {
// Params
if ($method === Method::Get) {
$params = $request->getQueryParams();
} else {
$params = Json::decode((string)$request->getBody());

Check failure on line 51 in src/Sender/Frontend/Http/Router.php

View workflow job for this annotation

GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)

MixedAssignment

src/Sender/Frontend/Http/Router.php:51:21: MixedAssignment: Unable to determine the type that $params is being assigned to (see https://psalm.dev/032)

Check failure on line 51 in src/Sender/Frontend/Http/Router.php

View workflow job for this annotation

GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)

MixedAssignment

src/Sender/Frontend/Http/Router.php:51:21: MixedAssignment: Unable to determine the type that $params is being assigned to (see https://psalm.dev/032)
\is_array($params) or $params = [];
}
} catch (\Throwable) {
$params = [];
}

/** @var mixed $message */
$message = $handler($request);
$message = $handler(...$params);

return new Response(
200,
Expand Down
2 changes: 1 addition & 1 deletion src/Traffic/Dispatcher/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class Http implements Dispatcher
public function __construct(
iterable $middlewares = [],
array $handlers = [],
private bool $silentMode = false,
private readonly bool $silentMode = false,
) {
// Init HTTP parser.
$this->parser = new Parser\Http();
Expand Down
2 changes: 1 addition & 1 deletion src/Traffic/Parser/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static function getBlock(StreamClient $stream): string
private function parseBody(StreamClient $stream, ServerRequestInterface $request): ServerRequestInterface
{
// Methods have body
if (!\in_array($request->getMethod(), ['POST', 'PUT', 'PATCH'], true)) {
if (!\in_array($request->getMethod(), ['POST', 'PUT', 'PATCH', 'DELETE'], true)) {
return $request;
}

Expand Down

0 comments on commit c2c71f8

Please sign in to comment.