-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Add Request::isStateless
method
#57852
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
53e5d30
to
5719dcb
Compare
Request::isStateless
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.
The new method should also be documented in the changelog file of the HttpFoundation component.
466cf5b
to
aa9e241
Compare
I tried to resolve the suggestion from @fabpot (#57852 (comment)) in the latest commit aa9e241 If we want to have only one place to deal with
This may be done by having a nullable boolean as return type of the isStateless method. That doesn't change a lot to the check WDYT ? |
having Code wanting to guard session reads will only need a boolean anyway (as they don't need to distinguish the default case). |
|
After my comment in #57854 (comment), I'm wondering if this is common enough to deserve a dedicated method. I feel like this builds on a wrong definition of the _stateless attribute. |
I'm not sure to understand where is the wrong definition
If it doesn't force the session to be stateless, then this check shouldn't exists symfony/src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php Lines 213 to 219 in c852b8b
And even if it's still a declaration, a way to know if the request is stateless should exists (in order to know if the session is useful/usable or not) and therefore a method would be better than having to know which private attribute is used. |
a17bfcd
to
9685160
Compare
Isn't |
Do you have a suggestion @MatTheCat ? "ShouldBeStateless" ? I understand |
|
Currently there is already some And |
When you configure a route stateless, you’re asking Symfony to warn you if the session is used. This does not offer any guarantee regarding the fact the session is used or not. As such, you cannot use this information to tell if the request is stateless or not. That’s why I think
Do you have use-cases in mind where a setter would make sense (if yes the name would be wrong the same way it is wrong for the getter)? 🤔 |
IMHO part of my misunderstanding come from the fact that
No, it was just to be used in Symfony code (in order to avoid having to know the private attribute when setting it, but using the getter when accessing it). |
I'd rather be 👎 here, reading the attribute is fine, and the setter doesn't really make sense to me. This gives too much visibility to the setting IMHO. |
Symfony does not enforce requests to be fully stateless so |
Yes, and personally I never used stateless request, I just needed a check because the request was declared stateless when I use stateless firewall... |
I have worked on several applications that made unnecessarily heavy use of the session before the decision was made to transition towards a RESTful API. It has always been hard to trace down where the stateless request processing is "tainted" by an unexpected session access. I think, Symfony could implement tooling to help with such a transition. Maybe this PR wasn't the right way (and the now-reverted logic for auto-flagging requests in stateless firewalls wasn't either), but I think we should continue talking about how we could tackle stateful/stateless requests better. Maybe we should start over with an issue where we could discuss the topic? |
Do you think the discussion could be done in the issue #57502 @derrabus or it would require a different one ? |
reading PRs/issues/discussions on such request stateless topic, we can see the "misleading/misusage" of such point
I do think this is a good starting point yes (or use existing one?) |
I think asking the user to check everywhere in his code for
before accessing
getSession
is kinda verbose and rely on some internal knowledge about how symfony describe the request as stateless.It's easier for the developer to write
rather than having to know the "internal attribute" to check
So I propose to introduce this method as a facade to the internal attribute.