fix(JsonResponse): better protocol header

This commit is contained in:
Jérémy Dufraisse 2023-02-26 01:32:14 +01:00
parent e4cdba842c
commit b3c88781d7

View File

@ -128,7 +128,7 @@ class JsonResponse implements JsonSerializable
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;