Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
ro0NL wants to merge2 commits intosymfony:masterfromro0NL:forwardrequest-check-response
Closed

[WebProfilerBundle] Imply forward request by a new X-Previous-Debug-Token header#22447

ro0NL wants to merge2 commits intosymfony:masterfromro0NL:forwardrequest-check-response

Conversation

@ro0NL
Copy link
Contributor

@ro0NLro0NL commentedApr 15, 2017
edited
Loading

QA
Branch?4.1
New feature?yes
BC breaks?no
Deprecations?yes
Tests pass?yes
Fixed tickets#...
LicenseMIT
Doc PRsymfony/symfony-docs#...

TLDR; imply a "forwarded" request in the profiler if onereturns 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.

publicfunctionindexAction(Request$request){$bar1 =$this->forward(__CLASS__.'::barAction');$bar2 =$this->forward(__CLASS__.'::bar2Action');return$bar1;}

It shows the request was forwarded tobar2Action. This changes that, so thatbarAction is shown instead. No forward is implied if a new response was returned byindexAction.

image

Note we dont really need the collector in the framework bundle anymore with this approach. deprecated it.

Copy link
Contributor

@aitboudadaitboudad left a comment

Choose a reason for hiding this comment

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

The tagkernel.event_subscriber can be removed forRequestDataCollector

* @param string $token
*
* @return Profile|null
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

unused method

Copy link
ContributorAuthor

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 ;-)

aitboudad reacted with laugh emoji
@aitboudad
Copy link
Contributor

@ro0NL theforward icon doesn't appear anymore, can you check why?
selection_084

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedApr 15, 2017
edited
Loading

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.

@aitboudad
Copy link
Contributor

I see now what's happen and but I'm not sure if it's expected or not.
Before, theforward icon is displayed if at least one request is forwarded and it doesn't matter if main request is forwarded or not But Now it appear only if the main request is forwarded.
Try with this:

publicfunctionindexAction(){$bar1 =$this->forward(__CLASS__.'::barAction');$bar2 =$this->forward(__CLASS__.'::bar2Action');return$this->render('index.html.twig');}

@ro0NL
Copy link
ContributorAuthor

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 exampleindexAction returns it's own response, it's not forwarded.

Note the sub-requests are still available in the request panel, nothing changed with that.

@nicolas-grekasnicolas-grekas added this to the3.4 milestoneApr 20, 2017
@nicolas-grekas
Copy link
Member

rebase needed
ping@javiereguiluz also since this is "profiler panel" related

ro0NL reacted with laugh emoji

@stof
Copy link
Member

this should be done against 3.4, not master, when rebasing (no need to reopen a different PR, as Github allows changing the branch)

@nicolas-grekasnicolas-grekas changed the base branch frommaster to3.4July 12, 2017 12:19
@HeahDude
Copy link
Contributor

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).

@ro0NL
Copy link
ContributorAuthor

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.

@HeahDude
Copy link
Contributor

the profiler assumes a forward request to the last sub request

This is not exact. The last forwarded request is considered since "forwarded" actions could be chained.

@ro0NL
Copy link
ContributorAuthor

Yet we imply a forward to bar2Action whereas you agree it should be bar1Action right?

The last forwarded request is considered since "forwarded" actions could be chained.

You mean ifA > B > C the profiler currently shows C for A? Indeed this PR would show B for A (and C for B).

@HeahDude
Copy link
Contributor

Sorry for the short answer above, let me try to explain myself better.

Your case:

publicfunctionindexAction(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{publicfunctionindexAction(Request$request)    {return$this->forward('BarController::barAction');    }}class BarController{publicfunctionbarAction(Request$request)    {return$this->forward('BazController::bazAction');    }}

Would show thebazAction profile in the toolbar as forwarded frombarAction (with a link to its profile) and this las one as forwarded fromindexAction.

SoA > B > C, would show the C profile in the toolbar with a link to B that links A.

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedAug 6, 2017
edited
Loading

is not a valid use case for forwarding IMHO, and such cannot be profiled correctly.

Agree it's a bit edgy, but this PR does fix it...

So A > B > C, would show the C profile in the toolbar with a link to B that links A.

Tested it and currently A shows B, and B shows C. So no change there.

Copy link
Contributor

@HeahDudeHeahDude left a comment

Choose a reason for hiding this comment

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

@ro0NL you're right, this change does not harm, but I left a question and I guess thisattribute is not needed anymore.

$profile->setIp('Unknown');
}

if ($prevToken =$response->headers->get('X-Debug-Token')) {
Copy link
Contributor

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?

Copy link
ContributorAuthor

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 headeralready, we assume a forwarded request. Thats the trick here.

Copy link
ContributorAuthor

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 aX-Previous-Debug-Token in RequestDataCollector we know it was forwarded (it had a x-debug-token previously).

@ro0NL
Copy link
ContributorAuthor

@HeahDude good catch, ive removed the_forwarded attribute.

@javiereguiluz could you have a look? Is the change clear for you?

@javiereguiluz
Copy link
Member

@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:

Doesn't this make any sub request a forwarded one?

If that's true ... isn't it wrong? We've never considered sub-request as forwarded requests, right?

@ro0NL
Copy link
ContributorAuthor

but I wouldn't mind if that remains unsolved.

Same, but experienced this issue (once now :)) whenadditionally 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.

If that's true ... isn't it wrong?

Not really, every sub request simply gets aX-Debug-Token. Nothing new here.

Thus when we return a sub request we basically return a responsewhich already has aX-Debug-Token (otherwise this wont happen, as the profiler assigns it).

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 aX-Debug-Previous-Token we know we returned a forwarded response.

That's robust to me.

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedSep 12, 2017
edited
Loading

@javiereguiluz other fix is it also works if you dont use forward(), ie dont extend from base controller. Thats nice actually.

@nicolas-grekas
Copy link
Member

@ro0NL rebase needed again sorry

@nicolas-grekas
Copy link
Member

Moving to 4.1. Rebase on master might be needed, where PHP 7.1 features can be used btw.

@nicolas-grekasnicolas-grekas modified the milestones:3.4,4.1Oct 8, 2017
@fabpot
Copy link
Member

LGTM. Needs to be reworked to take into account that this will be merged into 4.1 (mostly deprecation messages).

@ro0NLro0NL changed the base branch from3.4 tomasterFebruary 9, 2018 13:32
@ro0NL
Copy link
ContributorAuthor

ro0NL commentedFeb 9, 2018
edited
Loading

@fabpot good to go. However something else is bugging me:

image

(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)

image

f561d2 should be5a8b10 here (which is what this PR solves)

So i dont understand whyx-debug-token-link resolves different currently 🤔 moreover shouldnt it just be the current token instead?

Also not sure if you want me to apply fabbot.io patch..

edit:X-Debug-Token-Link is only set wrong in the profiler. THe actual HTTP header value is indeed linking to the current token.

@ro0NLro0NL changed the title[WebProfilerBundle] Indicate forward controller based on response headers[WebProfilerBundle] Imply forward request by a new X-Previous-Debug-Token headerFeb 9, 2018
@fabpot
Copy link
Member

@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.

@ro0NL
Copy link
ContributorAuthor

Correct, i confused deps with framework bundle. Means safety checks in templates (collector.forwardtoken|default(null)) are actually not needed 🎉

Now updated. Ill have a look at wrongX-Debug-Token-Link in profiler soonish, that's unrelated.

@fabpot
Copy link
Member

Thank you@ro0NL.

@fabpotfabpot closed thisFeb 12, 2018
fabpot added a commit that referenced this pull requestFeb 12, 2018
…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.```phppublic 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`.![image](https://cloud.githubusercontent.com/assets/1047696/25064022/e24d999e-21f1-11e7-8f94-afa3fad7462f.png)~~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
@ro0NLro0NL deleted the forwardrequest-check-response branchFebruary 12, 2018 18:26
@fabpotfabpot mentioned this pull requestMay 7, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

+2 more reviewers

@HeahDudeHeahDudeHeahDude left review comments

@aitboudadaitboudadaitboudad approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.1

Development

Successfully merging this pull request may close these issues.

8 participants

@ro0NL@aitboudad@nicolas-grekas@stof@HeahDude@javiereguiluz@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp