diff --git a/src/http-message/src/Server/Response.php b/src/http-message/src/Server/Response.php index ff645c74c..c19546f1c 100755 --- a/src/http-message/src/Server/Response.php +++ b/src/http-message/src/Server/Response.php @@ -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(); + } } /** diff --git a/src/http-server/src/Server.php b/src/http-server/src/Server.php index 70dc3f914..9cfd8886b 100644 --- a/src/http-server/src/Server.php +++ b/src/http-server/src/Server.php @@ -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); + } } }