Revert to implicitly supporting HEAD..

This commit is contained in:
flash 2024-03-28 23:27:04 +00:00
parent 3fcedb55ef
commit 9d5b050b89
2 changed files with 6 additions and 7 deletions

View file

@ -1 +1 @@
0.2403.282307
0.2403.282326

View file

@ -113,9 +113,6 @@ class HttpRouter implements IRouter {
if(trim($method) !== $method)
throw new InvalidArgumentException('$method may start or end with whitespace');
if($method === 'GET')
$this->add('HEAD', $path, $handler);
$prepared = self::preparePath($path, false);
if($prepared === false) {
if(str_ends_with($path, '/'))
@ -173,6 +170,8 @@ class HttpRouter implements IRouter {
$method = strtoupper($method);
if(array_key_exists($method, $methods))
$handler = $methods[$method];
elseif($method === 'HEAD' && array_key_exists('GET', $methods))
$handler = $methods['GET'];
return new ResolvedRouteInfo($middlewares, array_keys($methods), $handler, $args);
}
@ -228,7 +227,7 @@ class HttpRouter implements IRouter {
}
}
self::output($response->toResponse());
self::output($response->toResponse(), $request->getMethod() !== 'HEAD');
}
public function writeErrorPage(HttpResponseBuilder $response, HttpRequest $request, int $statusCode): void {
@ -236,7 +235,7 @@ class HttpRouter implements IRouter {
$this->errorHandler->handle($response, $request, $response->getStatusCode(), $response->getStatusText());
}
public static function output(HttpResponse $response): void {
public static function output(HttpResponse $response, bool $includeBody): void {
$version = $response->getHttpVersion();
header(sprintf(
'HTTP/%d.%d %03d %s',
@ -255,7 +254,7 @@ class HttpRouter implements IRouter {
header(sprintf('%s: %s', $name, (string)$line));
}
if($response->hasContent())
if($includeBody && $response->hasContent())
echo (string)$response->getContent();
}
}