Skip to content

Commit c6cadf2

Browse files
Merge pull request dingo#1777 from specialtactics/bugfix/dont-set-empty-content-type-header
Ensure content-type header is not empty before setting it (dingo#1736)
2 parents e081cf6 + 0d8b661 commit c6cadf2

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)