Adapte HEAD request

This commit is contained in:
huangzhhui 2020-01-28 18:11:01 +08:00
parent b5133f88fe
commit 67dd1ccb71
2 changed files with 11 additions and 3 deletions

View File

@ -37,7 +37,7 @@ class Response extends \Hyperf\HttpMessage\Base\Response implements Sendable
/**
* Handle response and send.
*/
public function send()
public function send(bool $withContent = true)
{
if (! $this->getSwooleResponse()) {
return;
@ -48,7 +48,11 @@ class Response extends \Hyperf\HttpMessage\Base\Response implements Sendable
if ($content instanceof FileInterface) {
return $this->swooleResponse->sendfile($content->getFilename());
}
$this->swooleResponse->end($content->getContents());
if ($withContent) {
$this->swooleResponse->end($content->getContents());
} else {
$this->swooleResponse->end();
}
}
/**

View File

@ -117,7 +117,11 @@ class Server implements OnRequestInterface, MiddlewareInitializerInterface
if (! isset($psr7Response) || ! $psr7Response instanceof Sendable) {
return;
}
$psr7Response->send();
if ($psr7Request->getMethod() === 'HEAD') {
$psr7Response->send(false);
} else {
$psr7Response->send(true);
}
}
}