diff --git a/src/JsonResponse.php b/src/JsonResponse.php index be9cc62..639ce55 100644 --- a/src/JsonResponse.php +++ b/src/JsonResponse.php @@ -125,10 +125,10 @@ class JsonResponse implements JsonSerializable * * @return $this */ - public function sendHeaders(): JsonResponse + public function sendHeaders(): JsonResponse { // headers have already been sent by the developer - if (!headers_sent()) { + if (!headers_sent() && !in_array(php_sapi_name(), ['cli', 'cli-server',' phpdbg'], true)) { // headers foreach ($this->headers as $name => $value) { @@ -137,7 +137,8 @@ class JsonResponse implements JsonSerializable // status $statusText = self::HTTP_CODES[$this->code]; - header("HTTP/1.0 {$this->code} $statusText"); + $protocol = !empty($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; + header("$protocol {$this->code} $statusText"); } return $this;