From 0d5f2b2bd9458d71e3ed57aa34e3a43c081111c4 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 2 May 2021 09:07:09 +1000 Subject: [PATCH] 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;