Skip to content

Commit

Permalink
Merge pull request #1777 from specialtactics/bugfix/dont-set-empty-co…
Browse files Browse the repository at this point in the history
…ntent-type-header

Ensure content-type header is not empty before setting it (#1736)
  • Loading branch information
specialtactics authored May 1, 2021
2 parents e081cf6 + 0d8b661 commit c6cadf2
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 c6cadf2

Please sign in to comment.