From 0d5f2b2bd9458d71e3ed57aa34e3a43c081111c4 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 2 May 2021 09:07:09 +1000 Subject: [PATCH 1/2] Ensure content-type header is not empty before setting it --- src/Http/Response.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Http/Response.php b/src/Http/Response.php index b9fc5ddf..792a748a 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -142,7 +142,11 @@ public function morph($format = 'json') $defaultContentType = $this->headers->get('Content-Type'); - $this->headers->set('Content-Type', $formatter->getContentType()); + // If we have no content, we don't want to set this header, as it will be blank + $contentType = $formatter->getContentType(); + if (!empty($contentType)) { + $this->headers->set('Content-Type', $formatter->getContentType()); + } $this->fireMorphedEvent(); @@ -153,7 +157,9 @@ public function morph($format = 'json') } elseif (is_array($this->content) || $this->content instanceof ArrayObject || $this->content instanceof Arrayable) { $this->content = $formatter->formatArray($this->content); } else { - $this->headers->set('Content-Type', $defaultContentType); + if (!empty($defaultContentType)) { + $this->headers->set('Content-Type', $defaultContentType); + } } return $this; From 0d8b66163d258897bef6dee00fe5d72a10b2abb8 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 2 May 2021 09:09:02 +1000 Subject: [PATCH 2/2] cs --- src/Http/Response.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Http/Response.php b/src/Http/Response.php index 792a748a..29a0a847 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -144,7 +144,7 @@ public function morph($format = 'json') // If we have no content, we don't want to set this header, as it will be blank $contentType = $formatter->getContentType(); - if (!empty($contentType)) { + if (! empty($contentType)) { $this->headers->set('Content-Type', $formatter->getContentType()); } @@ -157,7 +157,7 @@ public function morph($format = 'json') } elseif (is_array($this->content) || $this->content instanceof ArrayObject || $this->content instanceof Arrayable) { $this->content = $formatter->formatArray($this->content); } else { - if (!empty($defaultContentType)) { + if (! empty($defaultContentType)) { $this->headers->set('Content-Type', $defaultContentType); } }