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

@ -125,10 +125,10 @@ class JsonResponse implements JsonSerializable
* *
* @return $this * @return $this
*/ */
public function sendHeaders(): JsonResponse public function sendHeaders(): JsonResponse
{ {
// headers have already been sent by the developer // 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 // headers
foreach ($this->headers as $name => $value) { foreach ($this->headers as $name => $value) {
@ -137,7 +137,8 @@ class JsonResponse implements JsonSerializable
// status // status
$statusText = self::HTTP_CODES[$this->code]; $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; return $this;