Added html content sniffer
This commit is contained in:
parent
1f433694d2
commit
93e578e555
|
@ -48,6 +48,10 @@ class ErrorHandler implements MiddlewareInterface
|
||||||
$statusCode = $response->getStatusCode();
|
$statusCode = $response->getStatusCode();
|
||||||
$contentType = $response->getHeader('content-type');
|
$contentType = $response->getHeader('content-type');
|
||||||
$contentType = array_shift($contentType);
|
$contentType = array_shift($contentType);
|
||||||
|
if (!$contentType && strpos($response->getBody(), '<html') !== false) {
|
||||||
|
$contentType = 'text/html';
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$statusCode < 400
|
$statusCode < 400
|
||||||
|| !$response instanceof Response
|
|| !$response instanceof Response
|
||||||
|
|
|
@ -143,4 +143,23 @@ class ErrorHandlerTest extends TestCase
|
||||||
$return = $errorHandler->process($request, $returnResponseHandler);
|
$return = $errorHandler->process($request, $returnResponseHandler);
|
||||||
$this->assertEquals($psrResponse, $return);
|
$this->assertEquals($psrResponse, $return);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Middleware\ErrorHandler::process
|
||||||
|
*/
|
||||||
|
public function testProcessContentTypeSniffer()
|
||||||
|
{
|
||||||
|
/** @var ServerRequestInterface|MockObject $request */
|
||||||
|
$request = $this->createMock(ServerRequestInterface::class);
|
||||||
|
/** @var TwigLoader|MockObject $twigLoader */
|
||||||
|
$twigLoader = $this->createMock(TwigLoader::class);
|
||||||
|
$response = new Response('<!DOCTYPE html><html><body><h1>Hi!</h1></body></html>', 500);
|
||||||
|
$returnResponseHandler = new ReturnResponseMiddlewareHandler($response);
|
||||||
|
|
||||||
|
/** @var ErrorHandler|MockObject $errorHandler */
|
||||||
|
$errorHandler = new ErrorHandler($twigLoader);
|
||||||
|
|
||||||
|
$return = $errorHandler->process($request, $returnResponseHandler);
|
||||||
|
$this->assertEquals($response, $return);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue