-
Notifications
You must be signed in to change notification settings - Fork 19
Disable and enable debug bar #21
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
Changes from 6 commits
6f5d5d5
eb2cb2d
1e9dc62
43242c5
c344014
230d401
bb59bfe
c25e703
5bf435c
d584e06
d49a687
3ff0af2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,11 @@ | |
*/ | ||
final class PhpDebugBarMiddleware implements MiddlewareInterface | ||
{ | ||
const FORCE_KEY = 'X-Debug-Bar'; | ||
const FORCE_HEADER = self::FORCE_KEY; | ||
const FORCE_COOKIE = self::FORCE_KEY; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not really useful, because it repeats the same thing, so we can reuse the same thing, too |
||
const FORCE_ATTRIBUTE = self::FORCE_KEY; | ||
|
||
protected $debugBarRenderer; | ||
|
||
public function __construct(DebugBarRenderer $debugbarRenderer) | ||
|
@@ -41,7 +46,13 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface | |
|
||
$response = $handler->handle($request); | ||
|
||
if (!$this->isHtmlAccepted($request)) { | ||
$forceHeaderValue = $request->getHeaderLine(self::FORCE_HEADER); | ||
$forceCookieValue = $request->getCookieParams()[self::FORCE_COOKIE] ?? ''; | ||
$forceAttibuteValue = $request->getAttribute(self::FORCE_ATTRIBUTE, ''); | ||
$isForceEnable = in_array('true', [$forceHeaderValue, $forceCookieValue, $forceAttibuteValue], true); | ||
$isForceDisable = in_array('false', [$forceHeaderValue, $forceCookieValue, $forceAttibuteValue], true); | ||
|
||
if ($isForceDisable || (!$isForceEnable && !$this->isHtmlAccepted($request))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Problem is, some middlewares will just return 302 response (redirect somewhere), and are unaware of the debug bar middleware present. So we need to check for 302 at least additionally. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about other redirects? https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections You have right - redirect is possible, but sometimes you want to debug request / response before redirection - this PR allow to do that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's by using |
||
return $response; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it
public const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better naming:
X-Disable-Debug-Bar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this case should name
X-Enable-Debug-Bar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍