Skip to content

Commit a67bd42

Browse files
committed
Check response for avoid inject debugbar on json ajax
1 parent 16a13cc commit a67bd42

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/LaravelDebugbar.php

+27
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ public function modifyResponse(Request $request, Response $response)
839839
&& !$this->isJsonRequest($request, $response)
840840
&& $response->getContent() !== false
841841
&& in_array($request->getRequestFormat(), [null, 'html'], true)
842+
&& !$this->isJsonResponse($response)
842843
) {
843844
try {
844845
$this->injectDebugbar($response);
@@ -912,6 +913,32 @@ protected function isJsonRequest(Request $request, Response $response)
912913
return false;
913914
}
914915

916+
/**
917+
* @param \Symfony\Component\HttpFoundation\Response $response
918+
* @return bool
919+
*/
920+
protected function isJsonResponse(Response $response)
921+
{
922+
if ($response->headers->get('Content-Type') == 'application/json') {
923+
return true;
924+
}
925+
926+
try {
927+
$content = $response->getContent();
928+
929+
if (is_string($content)) {
930+
$content = json_decode($content, true);
931+
}
932+
933+
if (is_array($content)) {
934+
return true;
935+
}
936+
} catch (Exception $e) {
937+
}
938+
939+
return false;
940+
}
941+
915942
/**
916943
* Collects the data from the collectors
917944
*

0 commit comments

Comments
 (0)