Skip to content

Commit

Permalink
Ensure content-type header is not empty before setting it
Browse files Browse the repository at this point in the history
  • Loading branch information
specialtactics committed May 1, 2021
1 parent e081cf6 commit 0d5f2b2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
Expand Down

0 comments on commit 0d5f2b2

Please sign in to comment.