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

[HttpKernel] Fix session handling: decouple "save" from setting response "private"#25699

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

Merged
fabpot merged 1 commit intosymfony:3.4fromnicolas-grekas:fix-session
Jan 10, 2018

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedJan 6, 2018
edited
Loading

QA
Branch?3.4
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets-
LicenseMIT
Doc PR-

Fixes#25583 (comment) from@Tobion, and provides extra laziness for the "session" service, related tosymfony/recipes#333.

(deps=high failure will be fixed by merging to upper branches.)

/**
* @internal
*/
publicfunctionsetSessionFactory(callable$factory)
Copy link
MemberAuthor

@nicolas-grekasnicolas-grekasJan 6, 2018
edited
Loading

Choose a reason for hiding this comment

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

This provides extra laziness, needed to account forsymfony/recipes#333.

@nicolas-grekasnicolas-grekasforce-pushed thefix-session branch 2 times, most recently from9a1e7a0 tof3a8cc3CompareJanuary 6, 2018 15:01
if (null ===$session ||$request->hasSession()) {
return;
if (!$request->hasSession()) {
$request->setSessionFactory(function () {return$this->getSession(); });
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be more secure to isolate the listener in the closure by injecting it via ause instead of using$this that can be changed before executing the closure? Maybe I'm being paranoid, so just asking 😄

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Wow we never closed that far. Not sure it makes sense.
Here particularly there is nothing to close: the closure cannot be accessed.

*/
class SaveSessionListenerimplements EventSubscriberInterface
{
private$container;
Copy link
Member

Choose a reason for hiding this comment

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

please add explicit typehint for this property, typehint for constructor parameter is not the same as typehint for property

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

We actually removed such duplicate comments from the code base.

Copy link
Member

Choose a reason for hiding this comment

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

👎 on that, when one would do sth later with this code, he need to remember that perhaps he need to add that typehinting (eg, removing obtaining the parameter via constructor, changing visibility to public and so). I agree that for private it is no big deal, yet still.
And we do had already issues with field that was assumed to be type X, but in the end it wasnull|X, just not documented...

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I respect your opinion, but this is not the proper place to discuss this. Right now, this is just consistent with the code base.

Copy link
Member

Choose a reason for hiding this comment

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

I treat it same as with params, as long as we cannot typehint it on lang level, we do it in docblock ;)
Would be great if we would be able to do it with any var, like here with the property, but we are not there yet ;)
Well, I'm bet I just saw too many fuckups so I'm extra defensive...

@nicolas-grekas
Copy link
MemberAuthor

I'm going to split the extra-laziness part for 4.1

Status: needs work

@nicolas-grekas
Copy link
MemberAuthor

Extra-laziness removed, PR is now strictly a bug fix.

Status: needs review

Copy link
Contributor

@srozesroze left a comment

Choose a reason for hiding this comment

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

Wouldn't calling themigrate andsave methods on theSession object also start the session? i.e. we would need to sethasStarted totrue ?

It's also don't really get the difference betweenisStarted andhasStarted now 🤔Isn't it having some logic of the storage down to the Session object?

@nicolas-grekas
Copy link
MemberAuthor

I finally figured out a decent way to implement this, here we are.

@nicolas-grekasnicolas-grekasforce-pushed thefix-session branch 2 times, most recently from018ee58 to1eaeef6CompareJanuary 9, 2018 08:40
@nicolas-grekas
Copy link
MemberAuthor

wasStarted argument on the SessionBagProxy as a sort of hidden observable

that's exactly what theSessionBagProxy is for (and why it's internal also)

I'd properly decouple your logic

feel free to submit an alternate PR (but keep in mind this should remain a bug fix, no time for refactorizations.)

@sroze
Copy link
Contributor

that's exactly what the SessionBagProxy is for (and why it's internal also)

That's probably a good reason not to refactor 👍

@nicolas-grekasnicolas-grekasforce-pushed thefix-session branch 2 times, most recently fromdaca567 to294202eCompareJanuary 9, 2018 12:24
@nicolas-grekas
Copy link
MemberAuthor

and now green

return;
}

if ($session->isStarted() || ($sessioninstanceof Session && ((\method_exists(Session::class,'hasBeenStarted') &&$session->hasBeenStarted()) || (\method_exists(Session::class,'isEmpty') && !$session->isEmpty())))) {
Copy link
Contributor

@TobionTobionJan 10, 2018
edited
Loading

Choose a reason for hiding this comment

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

Why does it need to make the response uncachable when the session has been started but there is no data?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Because this is the semantic of the cache control header in HTTP: if the session is used, whatever it contains, then it means the page can be different for another user, and thus the page cannot be cached.
That's not new at all.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Hum, your question might be related to the isEmpty call on this line.
In fact this call is only required for maximum compatibility with soon-legacy versions of HttpKernel, where hasBeenStarted is not available.
We could also bump the minimum version requirement from 3.3 to 3.4.4.
I'll do that :)

@nicolas-grekasnicolas-grekasforce-pushed thefix-session branch 2 times, most recently from97847c0 tof0bd401CompareJanuary 10, 2018 08:22
@nicolas-grekas
Copy link
MemberAuthor

Minimum version of http-foundation bumped.

@fabpot
Copy link
Member

Thank you@nicolas-grekas.

@fabpotfabpot merged commitf8727b8 intosymfony:3.4Jan 10, 2018
fabpot added a commit that referenced this pull requestJan 10, 2018
…tting response "private" (nicolas-grekas)This PR was merged into the 3.4 branch.Discussion----------[HttpKernel] Fix session handling: decouple "save" from setting response "private"| Q             | A| ------------- | ---| Branch?       | 3.4| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -Fixes#25583 (comment) from@Tobion, and provides extra laziness for the "session" service, related tosymfony/recipes#333.(deps=high failure will be fixed by merging to upper branches.)Commits-------f8727b8 [HttpKernel] Fix session handling: decouple "save" from setting response "private"
This was referencedJan 29, 2018
@nicolas-grekasnicolas-grekas deleted the fix-session branchFebruary 19, 2018 10:35
symfony-splitter pushed a commit to symfony/http-kernel that referenced this pull requestMar 30, 2018
…rivate automatically (Toflar)This PR was squashed before being merged into the 4.1-dev branch (closes #26681).Discussion----------Allow to easily ask Symfony not to set a response to private automatically| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets || License       | MIT| Doc PR        |This PR is related to the many discussions going on about the latest (Symfony 3.4+) changes regarding the way Symfony handles the session. I think we're almost there now, Symfony 4.1 automatically turns responses into `private` responses once the session is started and it's all done in the `AbstractSessionListener` where the session is also saved.In other issues/PRs (symfony/symfony#25583,symfony/symfony#25699,symfony/symfony#24988) it was agreed that setting the response to `private` if the session is started is a good default for Symfony. It was also agreed that setting it to `private` does not always make sense because you **can share a response** across sessions, it just requires a more complex caching setup with shared user context etc.So there must be an easy way to disable this behaviour. Right now it's very hard to do so because what you end up doing is basically decorating the `session_listener` which is very hard because you have to keep track on that over different Symfony versions as the base listener might get additional features etc.The [FOSCacheBundle](FriendsOfSymfony/FOSHttpCacheBundle#438) is already having this problem, [Contao](contao/core-bundle#1388) has the same issue and there will be probably more. Basically everyone that wants to share a response cache across the session will have to decorate the default listener. That's just too hard, so I came up with this solution. The header is easy. Every project can add that easily. It does not require any extension, configuration or adjustment of any service. It's clean, transparent and has absolutely no impact on "default" Symfony setups.Would be happy to have some feedback before 4.1 freeze.Commits-------0f36710 Allow to easily ask Symfony not to set a response to private automatically
fabpot added a commit that referenced this pull requestMar 30, 2018
…rivate automatically (Toflar)This PR was squashed before being merged into the 4.1-dev branch (closes#26681).Discussion----------Allow to easily ask Symfony not to set a response to private automatically| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets || License       | MIT| Doc PR        |This PR is related to the many discussions going on about the latest (Symfony 3.4+) changes regarding the way Symfony handles the session. I think we're almost there now, Symfony 4.1 automatically turns responses into `private` responses once the session is started and it's all done in the `AbstractSessionListener` where the session is also saved.In other issues/PRs (#25583,#25699,#24988) it was agreed that setting the response to `private` if the session is started is a good default for Symfony. It was also agreed that setting it to `private` does not always make sense because you **can share a response** across sessions, it just requires a more complex caching setup with shared user context etc.So there must be an easy way to disable this behaviour. Right now it's very hard to do so because what you end up doing is basically decorating the `session_listener` which is very hard because you have to keep track on that over different Symfony versions as the base listener might get additional features etc.The [FOSCacheBundle](FriendsOfSymfony/FOSHttpCacheBundle#438) is already having this problem, [Contao](contao/core-bundle#1388) has the same issue and there will be probably more. Basically everyone that wants to share a response cache across the session will have to decorate the default listener. That's just too hard, so I came up with this solution. The header is easy. Every project can add that easily. It does not require any extension, configuration or adjustment of any service. It's clean, transparent and has absolutely no impact on "default" Symfony setups.Would be happy to have some feedback before 4.1 freeze.Commits-------0f36710 Allow to easily ask Symfony not to set a response to private automatically
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

+4 more reviewers

@TobionTobionTobion left review comments

@srozesrozesroze left review comments

@keraduskeraduskeradus left review comments

@PierstovalPierstovalPierstoval left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.4

Development

Successfully merging this pull request may close these issues.

7 participants

@nicolas-grekas@sroze@fabpot@Tobion@keradus@Pierstoval@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp