-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] [RFC] Improve stateless request handling #57502
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
Comments
Indeed as I’ve commented on your pr, i think it make sens to me to expose a more higher public level of this internal data as the attribute _stateless is |
I think this discussion relates to this topic as well, so I thought I'd share. : #45025 |
I think it would simplify things a lot if stateless requests would act like the session does not exist, e.g. Otherwise you'd have to always check yourself if the request is stateless (both in the framework itself and in your own code). Some places in the Symfony framework have already been updated to include this check, but there are still some places remaining that are missing this check, resulting in bugs or unexpected behavior. I think there shouldn't be a use case to create/read/update/delete the session if you declare the route/request stateless. Regardless of this, in my opinion |
Thank you for this suggestion. |
Could I get a reply or should I close this? |
perhaps this comment can/must be linked to showcase how ppl can, in their code, handle the fact that there is a session or not |
Description
When a request is flagged as stateless, we're not supposed to use the session.
Still, this was often forgotten and I saw many fixes in Symfony codebase like
#57372
#54742
#51350
I think there is something to improve in other to have easier stateless check and/or integrate the check inside
hasSession/getSession
.First, to me, the
_attribute
seems internal to Symfony and it's not perfect to ask the user to check forso I would propose to introduce
Request::isStateless
which could be done this way 05d4852Second, since there is an exception/warning checking if the session was used when the request is stateless
cf
symfony/src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php
Lines 209 to 219 in c852b8b
what about including the
isStateless
check directly inhasSession
andgetSession
method ?Example
We could have
and
hasSession
returns false when the request is stateless.hasSession
returns true and people will have to checkhasSession && !isStateless
to callgetSession
.Of course, this would be introduced in a BC way with
in Symfony 7.
WDYT ? Is there a reason to allowing accessing the session when the request is stateless ?
The text was updated successfully, but these errors were encountered: