@@ -46,7 +46,7 @@ class Toolbar
4646 * Indicates if the current request is a custom AJAX-like request
4747 * (HTMX, Unpoly, Turbo, etc.) that expects clean HTML fragments.
4848 */
49- protected bool $ isCustomAjax = false ;
49+ protected bool $ isDisabled = false ;
5050
5151 /**
5252 * Collectors to be used and displayed.
@@ -413,11 +413,8 @@ public function prepare(?RequestInterface $request = null, ?ResponseInterface $r
413413
414414 $ format = $ response ->getHeaderLine ('content-type ' );
415415
416- foreach ($ config ->disableOnHeaders as $ header ) {
417- if ($ request ->hasHeader ($ header )) {
418- $ this ->isCustomAjax = true ;
419- break ;
420- }
416+ if ($ this ->shouldDisableToolbar ($ request , $ config ->disableOnHeaders )) {
417+ $ this ->isDisabled = true ;
421418 }
422419
423420 // Non-HTML formats should not include the debugbar
@@ -558,4 +555,35 @@ protected function format(string $data, string $format = 'html'): string
558555
559556 return $ output ;
560557 }
558+
559+ /**
560+ * Determine if the toolbar should be disabled based on the request headers.
561+ *
562+ * This method allows checking both the presence of headers and their expected values.
563+ *
564+ * @param array<string, string|null> $headersToDisableToolbar
565+ *
566+ * @return bool True if any header condition matches; false otherwise.
567+ */
568+ private function shouldDisableToolbar (IncomingRequest $ request , array $ headersToDisableToolbar ): bool
569+ {
570+ foreach ($ headersToDisableToolbar as $ headerName => $ expectedValue ) {
571+ if (! $ request ->hasHeader ($ headerName )) {
572+ continue ; // header not present, skip
573+ }
574+
575+ // If expectedValue is null, only presence is enough
576+ if ($ expectedValue === null ) {
577+ return true ;
578+ }
579+
580+ $ headerValue = strtolower ($ request ->getHeaderLine ($ headerName ));
581+
582+ if ($ headerValue === strtolower ($ expectedValue )) {
583+ return true ;
584+ }
585+ }
586+
587+ return false ;
588+ }
561589}
0 commit comments