Revert to implicitly supporting HEAD..
This commit is contained in:
parent
3fcedb55ef
commit
9d5b050b89
|
@ -113,9 +113,6 @@ class HttpRouter implements IRouter {
|
||||||
if(trim($method) !== $method)
|
if(trim($method) !== $method)
|
||||||
throw new InvalidArgumentException('$method may start or end with whitespace');
|
throw new InvalidArgumentException('$method may start or end with whitespace');
|
||||||
|
|
||||||
if($method === 'GET')
|
|
||||||
$this->add('HEAD', $path, $handler);
|
|
||||||
|
|
||||||
$prepared = self::preparePath($path, false);
|
$prepared = self::preparePath($path, false);
|
||||||
if($prepared === false) {
|
if($prepared === false) {
|
||||||
if(str_ends_with($path, '/'))
|
if(str_ends_with($path, '/'))
|
||||||
|
@ -173,6 +170,8 @@ class HttpRouter implements IRouter {
|
||||||
$method = strtoupper($method);
|
$method = strtoupper($method);
|
||||||
if(array_key_exists($method, $methods))
|
if(array_key_exists($method, $methods))
|
||||||
$handler = $methods[$method];
|
$handler = $methods[$method];
|
||||||
|
elseif($method === 'HEAD' && array_key_exists('GET', $methods))
|
||||||
|
$handler = $methods['GET'];
|
||||||
|
|
||||||
return new ResolvedRouteInfo($middlewares, array_keys($methods), $handler, $args);
|
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 {
|
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());
|
$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();
|
$version = $response->getHttpVersion();
|
||||||
header(sprintf(
|
header(sprintf(
|
||||||
'HTTP/%d.%d %03d %s',
|
'HTTP/%d.%d %03d %s',
|
||||||
|
@ -255,7 +254,7 @@ class HttpRouter implements IRouter {
|
||||||
header(sprintf('%s: %s', $name, (string)$line));
|
header(sprintf('%s: %s', $name, (string)$line));
|
||||||
}
|
}
|
||||||
|
|
||||||
if($response->hasContent())
|
if($includeBody && $response->hasContent())
|
||||||
echo (string)$response->getContent();
|
echo (string)$response->getContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue