diff --git a/src/Format/NoBody.php b/src/Format/NoBody.php new file mode 100644 index 0000000..0f609d5 --- /dev/null +++ b/src/Format/NoBody.php @@ -0,0 +1,26 @@ +getBody()->write(''); + } else { + $result = response()->withBody(new Stream()); + } + return $result; + } +} \ No newline at end of file diff --git a/src/Handler.php b/src/Handler.php index 8ba420f..139ef67 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -7,6 +7,7 @@ use Closure; use Kiri\Router\Format\ArrayFormat; use Kiri\Router\Format\IFormat; use Kiri\Router\Format\MixedFormat; +use Kiri\Router\Format\NoBody; use Kiri\Router\Format\OtherFormat; use Kiri\Router\Format\ResponseFormat; use Kiri\Router\Format\VoidFormat; @@ -36,13 +37,14 @@ class Handler implements RequestHandlerInterface /** * @param array|Closure $handler + * @param string $method * @param array $parameter * @param ReflectionNamedType|null $reflectionType - * @throws ReflectionException * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface + * @throws ReflectionException */ - public function __construct(public array|Closure $handler, public array $parameter, public ?ReflectionNamedType $reflectionType) + public function __construct(public array|Closure $handler, string $method, public array $parameter, public ?ReflectionNamedType $reflectionType) { $this->container = \Kiri::getDi(); if ($this->reflectionType != null) { @@ -50,6 +52,9 @@ class Handler implements RequestHandlerInterface } else { $this->format = $this->container->get(MixedFormat::class); } + if ($method === 'HEAD') { + $this->format = $this->container->get(NoBody::class); + } }