File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ class Alert implements Output
99{
1010 public function output (Collection $ detectedQueries , Response $ response )
1111 {
12- if ($ response ->isRedirection ()) {
12+ if (stripos ( $ response -> headers -> get ( ' Content-Type ' ), ' text/html ' ) !== 0 || $ response ->isRedirection ()) {
1313 return ;
1414 }
1515
Original file line number Diff line number Diff line change 11<?php
2+
23namespace BeyondCode \QueryDetector \Outputs ;
4+
35use Illuminate \Support \Collection ;
46use Symfony \Component \HttpFoundation \Response ;
57
68class Console implements Output
79{
810 public function output (Collection $ detectedQueries , Response $ response )
911 {
10- if ($ response ->isRedirection ()) {
12+ if (stripos ( $ response -> headers -> get ( ' Content-Type ' ), ' text/html ' ) !== 0 || $ response ->isRedirection ()) {
1113 return ;
1214 }
15+
1316 $ content = $ response ->getContent ();
17+
1418 $ outputContent = $ this ->getOutputContent ($ detectedQueries );
19+
1520 $ pos = strripos ($ content , '</body> ' );
21+
1622 if (false !== $ pos ) {
1723 $ content = substr ($ content , 0 , $ pos ) . $ outputContent . substr ($ content , $ pos );
1824 } else {
1925 $ content = $ content . $ outputContent ;
2026 }
27+
2128 // Update the new content and reset the content length
2229 $ response ->setContent ($ content );
30+
2331 $ response ->headers ->remove ('Content-Length ' );
2432 }
33+
2534 protected function getOutputContent (Collection $ detectedQueries )
2635 {
2736 $ output = '<script type="text/javascript"> ' ;
@@ -33,6 +42,7 @@ protected function getOutputContent(Collection $detectedQueries)
3342 }
3443 $ output .= "') " ;
3544 $ output .= '</script> ' ;
45+
3646 return $ output ;
3747 }
3848}
You can’t perform that action at this time.
0 commit comments