-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[WebProfilerBundle] Imply forward request by a new X-Previous-Debug-Token header #22447
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
Conversation
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.
The tag kernel.event_subscriber
can be removed for RequestDataCollector
* | ||
* @return Profile|null | ||
*/ | ||
public function getChildByToken($token) |
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.
unused method
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.
It's used in twig ;-)
@ro0NL the |
Not sure.. what code are you referring to? Assuming symfony-demo.. i installed the latest version but i dont get a forward; or im missing it somewhere else in the app. |
I see now what's happen and but I'm not sure if it's expected or not. public function indexAction()
{
$bar1 = $this->forward(__CLASS__.'::barAction');
$bar2 = $this->forward(__CLASS__.'::bar2Action');
return $this->render('index.html.twig');
} |
Imo. the arrow / "Forwarded to" implies the request was as-is forwarded to a sub-request, this is why i think the current behavior is misleading. In your example Note the sub-requests are still available in the request panel, nothing changed with that. |
rebase needed |
this should be done against 3.4, not master, when rebasing (no need to reopen a different PR, as Github allows changing the branch) |
I don't get the use case, isn't "forward" meant to return "the" response? This looks really weird to handle this. The forward feature should not be confused with making standard sub requests IMO (with were already profiled before #17589 btw). |
Well.. imo. whats weird is the profiler assumes a forward request to the last sub request, whereas we may forward to the first sub request. |
This is not exact. The last forwarded request is considered since "forwarded" actions could be chained. |
Yet we imply a forward to bar2Action whereas you agree it should be bar1Action right?
You mean if |
Sorry for the short answer above, let me try to explain myself better. Your case: public function indexAction(Request $request)
{
$bar1 = $this->forward(__CLASS__.'::barAction');
$bar2 = $this->forward(__CLASS__.'::bar2Action');
return $bar1;
} is not a valid use case for forwarding IMHO, and such cannot be profiled correctly. What I assumed when working on #17589 is: class FooController
{
public function indexAction(Request $request)
{
return $this->forward('BarController::barAction');
}
}
class BarController
{
public function barAction(Request $request)
{
return $this->forward('BazController::bazAction');
}
} Would show the So |
Agree it's a bit edgy, but this PR does fix it...
Tested it and currently A shows B, and B shows C. So no change there. |
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.
@@ -178,6 +178,10 @@ public function collect(Request $request, Response $response, \Exception $except | |||
$profile->setIp('Unknown'); | |||
} | |||
|
|||
if ($prevToken = $response->headers->get('X-Debug-Token')) { |
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.
Doesn't this make any sub request a forwarded one?
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.
Yes :) basically if the response has a x-debug-token header already, we assume a forwarded request. Thats the trick here.
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.
And thus if we have a X-Previous-Debug-Token
in RequestDataCollector we know it was forwarded (it had a x-debug-token previously).
@HeahDude good catch, ive removed the @javiereguiluz could you have a look? Is the change clear for you? |
@ro0NL the example you showed in the description is very very edgy to me. If this PR solves it, that's great ... but I wouldn't mind if that remains unsolved. My concern is this comment from @HeahDude:
If that's true ... isn't it wrong? We've never considered sub-request as forwarded requests, right? |
Same, but experienced this issue (once now :)) when additionally doing a sub request (just to trigger some logging, ignoring it's response). Yet the forwarded response was requested before that, the one we return. Might be solved by changing it's order on our side, sure :) (well.. not sure really, but i could try). However, the case, made me think of different approach, this PR.
Not really, every sub request simply gets a Thus when we return a sub request we basically return a response which already has a Now the profiler is updated to check if it has X-Debug-Token beforehand, if so, that becomes X-Debug-Previous-Token and again assigns a new X-Debug-Token. So only in this case we have 2 debug tokens. Consequently if we have a That's robust to me. |
@javiereguiluz other fix is it also works if you dont use forward(), ie dont extend from base controller. Thats nice actually. |
@ro0NL rebase needed again sorry |
Moving to 4.1. Rebase on master might be needed, where PHP 7.1 features can be used btw. |
LGTM. Needs to be reworked to take into account that this will be merged into 4.1 (mostly deprecation messages). |
@fabpot good to go. However something else is bugging me: (on master in case of a forward request) The token differs, the link goes to the actual subrequest made (which is the right one here actually :D)
So i dont understand why Also not sure if you want me to apply fabbot.io patch.. edit: |
@ro0NL The WebProfiler uses new methods on the data collector class, so it looks like some Composer constraints need to be adjusted so that the web profiler does not allow using an older version of the HTTP Kernel component. |
Correct, i confused deps with framework bundle. Means safety checks in templates ( Now updated. Ill have a look at wrong |
Thank you @ro0NL. |
…revious-Debug-Token header (ro0NL) This PR was squashed before being merged into the 4.1-dev branch (closes #22447). Discussion ---------- [WebProfilerBundle] Imply forward request by a new X-Previous-Debug-Token header | Q | A | ------------- | --- | Branch? | 4.1 | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> TLDR; imply a "forwarded" request in the profiler if one _returns_ a response with a x-debug-token set. Otherwise dont. ____ Currently a forward request is implied by the WDT/profiler based on the latest sub-request made, however the main request can return it's own response, or one from a non-latest sub-request. The current behavior is a bit misleading imo. ```php public function indexAction(Request $request) { $bar1 = $this->forward(__CLASS__.'::barAction'); $bar2 = $this->forward(__CLASS__.'::bar2Action'); return $bar1; } ``` It shows the request was forwarded to `bar2Action`. This changes that, so that `barAction` is shown instead. No forward is implied if a new response was returned by `indexAction`.  ~~Note we dont really need the collector in the framework bundle anymore with this approach.~~ deprecated it. Commits ------- 07dd09d [WebProfilerBundle] Imply forward request by a new X-Previous-Debug-Token header
TLDR; imply a "forwarded" request in the profiler if one returns a response with a x-debug-token set. Otherwise dont.
Currently a forward request is implied by the WDT/profiler based on the latest sub-request made, however the main request can return it's own response, or one from a non-latest sub-request. The current behavior is a bit misleading imo.
It shows the request was forwarded to
bar2Action
. This changes that, so thatbarAction
is shown instead. No forward is implied if a new response was returned byindexAction
.Note we dont really need the collector in the framework bundle anymore with this approach.deprecated it.