Skip to content

Commit 0d5f2b2

Browse files
Ensure content-type header is not empty before setting it
1 parent e081cf6 commit 0d5f2b2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Http/Response.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ public function morph($format = 'json')
142142

143143
$defaultContentType = $this->headers->get('Content-Type');
144144

145-
$this->headers->set('Content-Type', $formatter->getContentType());
145+
// If we have no content, we don't want to set this header, as it will be blank
146+
$contentType = $formatter->getContentType();
147+
if (!empty($contentType)) {
148+
$this->headers->set('Content-Type', $formatter->getContentType());
149+
}
146150

147151
$this->fireMorphedEvent();
148152

@@ -153,7 +157,9 @@ public function morph($format = 'json')
153157
} elseif (is_array($this->content) || $this->content instanceof ArrayObject || $this->content instanceof Arrayable) {
154158
$this->content = $formatter->formatArray($this->content);
155159
} else {
156-
$this->headers->set('Content-Type', $defaultContentType);
160+
if (!empty($defaultContentType)) {
161+
$this->headers->set('Content-Type', $defaultContentType);
162+
}
157163
}
158164

159165
return $this;

0 commit comments

Comments
 (0)