Skip to content

Commit ff74755

Browse files
committed
[BUGFIX] Don't try to amend content type when header not present
When the response from TYPO3 isn't 200 or content-type header isn't present for any other reason, the code to amend it is now skipped.
1 parent c5d3427 commit ff74755

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

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)