feat: make DebugToolbar smarter about detecting binary/streamed responses #9862
+177
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR enhances the
DebugToolbar's detection logic to support third-party libraries that bypass the framework's Response object (e.g., Dompdf).Currently, CodeIgniter relies solely on its internal
Responseobject to decide whether to inject the toolbar. However, many libraries output content directly using native PHPheader()andecho. In these cases, the Toolbar assumes the content is HTML and injects itself, which is often undesirable for binary streams.I've implemented a Native State Awareness mechanism in
Toolbar::prepare(). The toolbar now acts as a secondary guard, validating the environment's actual state before injection.This issue has been raised before by several community members on the forum. At the time, we were unable to clearly identify the root cause, as the behavior only manifests when third-party libraries bypass the framework’s abstraction layer and interact directly with native PHP output mechanisms.
After revisiting the problem with a deeper analysis of the runtime behavior, I was able to trace the issue to a mismatch between the framework’s assumed response state and the actual native PHP state. Based on that insight, this PR introduces a more resilient detection mechanism that addresses not only the originally reported cases, but also a broader class of similar issues.
See: https://forum.codeigniter.com/showthread.php?tid=82461
Checklist: