Skip to content

Commit 67d7756

Browse files
authored
Merge pull request #88 from helhum/fix-content-type-amend
2 parents c5d3427 + ff74755 commit 67d7756

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Classes/Middleware/TypoScriptRenderingMiddleware.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,18 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
7373
*/
7474
private function amendContentType(ResponseInterface $response, string $requestedContentType): ResponseInterface
7575
{
76+
if ($response->getStatusCode() !== 200
77+
|| !$response->hasHeader('Content-Type')
78+
) {
79+
return $response;
80+
}
7681
$originalContentTypeHeader = $response->getHeader('Content-Type')[0];
77-
if (strpos($originalContentTypeHeader, self::defaultContentType) === 0 && strpos($originalContentTypeHeader, $requestedContentType) === false) {
78-
$response = $response->withHeader('Content-Type', \str_replace(self::defaultContentType, $requestedContentType, $originalContentTypeHeader));
82+
if (strpos($originalContentTypeHeader, self::defaultContentType) !== 0
83+
|| strpos($originalContentTypeHeader, $requestedContentType) === 0
84+
) {
85+
return $response;
7986
}
80-
81-
return $response;
87+
return $response->withHeader('Content-Type', \str_replace(self::defaultContentType, $requestedContentType, $originalContentTypeHeader));
8288
}
8389

8490
/**

0 commit comments

Comments
 (0)