Skip to content

Exclude by default content-types !== 'text/html' #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/PhpDebugBarMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,24 @@ class PhpDebugBarMiddleware implements MiddlewareInterface
{
use DoublePassCompatibilityTrait;

/**
* @var DebugBarRenderer
*/
protected $debugBarRenderer;

public function __construct(DebugBarRenderer $debugbarRenderer)
/**
* @var bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe will be better to have some policy for that? Sometimes you want to debug json, but not generated pdf. With bool it's not possible. We can provide some read implmentation and simple interface to provide own.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree... not sure if I can get some time to think about it. We could add a special key '__debugbar' if it does not already exist . But I believe, going content-type-aware will need some more refactoring.

*/
protected $excludeNonHtmlContent;

/**
* @param DebugBarRenderer $debugbarRenderer
* @param bool $excludeNonHtmlContent Whether to disable debugbar on content-types != 'test/html'
*/
public function __construct(DebugBarRenderer $debugbarRenderer, $excludeNonHtmlContent=false)
{
$this->debugBarRenderer = $debugbarRenderer;
$this->excludeNonHtmlContent = $excludeNonHtmlContent;
}

/**
Expand All @@ -49,7 +62,10 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele

if ($this->isHtmlResponse($response)) {
return $this->attachDebugBarToResponse($response);
} elseif ($this->excludeNonHtmlContent) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test case

return $response;
}

return $this->prepareHtmlResponseWithDebugBar($response);
}

Expand Down