Skip to content

Commit 63434bd

Browse files
committed
Check header contains value helper function
1 parent 863ea99 commit 63434bd

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Diff for: src/PhpDebugBarMiddleware.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PhpMiddleware\PhpDebugBar;
44

55
use DebugBar\JavascriptRenderer as DebugBarRenderer;
6+
use Psr\Http\Message\MessageInterface;
67
use Psr\Http\Message\ResponseInterface;
78
use Psr\Http\Message\ServerRequestInterface;
89
use Zend\Diactoros\Response\HtmlResponse;
@@ -67,7 +68,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
6768
*/
6869
private function isHtmlResponse(ResponseInterface $response)
6970
{
70-
return strpos($response->getHeaderLine('Content-Type'), 'text/html') !== false;
71+
return $this->hasHeaderContains($response, 'Content-Type', 'text/html');
7172
}
7273

7374
/**
@@ -77,6 +78,18 @@ private function isHtmlResponse(ResponseInterface $response)
7778
*/
7879
private function isHtmlAccepted(ServerRequestInterface $request)
7980
{
80-
return strpos($request->getHeaderLine('Accept'), 'text/html') !== false;
81+
return $this->hasHeaderContains($request, 'Accept', 'text/html');
82+
}
83+
84+
/**
85+
* @param MessageInterface $message
86+
* @param string $headerName
87+
* @param string $value
88+
*
89+
* @return bool
90+
*/
91+
private function hasHeaderContains(MessageInterface $message, $headerName, $value)
92+
{
93+
return strpos($message->getHeaderLine($headerName), $value) !== false;
8194
}
8295
}

0 commit comments

Comments
 (0)