Skip to content

Commit

Permalink
Merge pull request #88 from helhum/fix-content-type-amend
Browse files Browse the repository at this point in the history
  • Loading branch information
helhum committed Nov 22, 2022
2 parents c5d3427 + ff74755 commit 67d7756
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Classes/Middleware/TypoScriptRenderingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,18 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
*/
private function amendContentType(ResponseInterface $response, string $requestedContentType): ResponseInterface
{
if ($response->getStatusCode() !== 200
|| !$response->hasHeader('Content-Type')
) {
return $response;
}
$originalContentTypeHeader = $response->getHeader('Content-Type')[0];
if (strpos($originalContentTypeHeader, self::defaultContentType) === 0 && strpos($originalContentTypeHeader, $requestedContentType) === false) {
$response = $response->withHeader('Content-Type', \str_replace(self::defaultContentType, $requestedContentType, $originalContentTypeHeader));
if (strpos($originalContentTypeHeader, self::defaultContentType) !== 0
|| strpos($originalContentTypeHeader, $requestedContentType) === 0
) {
return $response;
}

return $response;
return $response->withHeader('Content-Type', \str_replace(self::defaultContentType, $requestedContentType, $originalContentTypeHeader));
}

/**
Expand Down

0 comments on commit 67d7756

Please sign in to comment.