Skip to content

Commit 6c849ea

Browse files
committed
Add Response::getContentType method
1 parent fa5ad9d commit 6c849ea

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/Response.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public function __toString() : string
6767
if ($this->getHeader(ResponseHeader::DATE) === null) {
6868
$this->setDate();
6969
}
70-
if ($this->getHeader(ResponseHeader::CONTENT_TYPE) === null
71-
&& $this->getBody() !== '') {
70+
if ($this->getContentType() === null && $this->getBody() !== '') {
7271
$this->setContentType('text/html');
7372
}
7473
if ($this->hasDownload()) {
@@ -578,7 +577,7 @@ protected function negotiateCsp() : void
578577
if ($this->getBody() === '' || $this->hasDownload()) {
579578
return;
580579
}
581-
$contentType = (string) $this->getHeader(ResponseHeader::CONTENT_TYPE);
580+
$contentType = (string) $this->getContentType();
582581
if (!\str_contains($contentType, 'text/html')) {
583582
return;
584583
}
@@ -612,7 +611,7 @@ protected function negotiateCsp() : void
612611
*/
613612
protected function negotiateContentType() : void
614613
{
615-
if ($this->getHeader(ResponseHeader::CONTENT_TYPE) !== null) {
614+
if ($this->getContentType() !== null) {
616615
return;
617616
}
618617
if ($this->getBody() !== '') {
@@ -823,6 +822,16 @@ public function setContentType(string $mime, ?string $charset = 'UTF-8') : stati
823822
return $this;
824823
}
825824

825+
/**
826+
* Get the Content-Type header.
827+
*
828+
* @return string|null
829+
*/
830+
public function getContentType() : ?string
831+
{
832+
return $this->getHeader(ResponseHeader::CONTENT_TYPE);
833+
}
834+
826835
/**
827836
* Set the Content-Language header.
828837
*

0 commit comments

Comments
 (0)