-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Issues with the new Cookie management #11208
Comments
Cookies should be sent and encoded when responses contain |
I took a look at this and was able to reproduce the issue you were having. The dropped cookies on redirect were likely caused by the I was not able to reproduce the missing cookie data when the
Yes there is only one function in that middleware. It handles processing the incoming request, calling the 'next' middleware, and then encrypting cookies in the response generated by other middleware.
If your cookie is being set in a controller action, then that would happen inside of |
Add a new method to get a cookie value as a string. I considered changing how `getValue()` works but thought that had bigger compatibility implications. Instead I've modified the interface/implementation. Normally I would shy away from changing interfaces, but this is a very new class and the likelihood of there be user-space implementations is quite low. Refs #11208
#11209 will solve the problems I was able to reproduce here. |
Thank you Mark, I applied your changes and It correctly fixes all the issues I had (for these i commentend directly in the pull request). 😄 For completeness I had the issue with |
Add a new method to get a cookie value as a string. I considered changing how `getValue()` works but thought that had bigger compatibility implications. Instead I've modified the interface/implementation. Normally I would shy away from changing interfaces, but this is a very new class and the likelihood of there be user-space implementations is quite low. Refs cakephp#11208
Add a new method to get a cookie value as a string. I considered changing how `getValue()` works but thought that had bigger compatibility implications. Instead I've modified the interface/implementation. Normally I would shy away from changing interfaces, but this is a very new class and the likelihood of there be user-space implementations is quite low. Refs cakephp#11208
This is a (multiple allowed):
bug
enhancement
feature-discussion (RFC)
CakePHP Version: 3.5.2
Platform and Target: Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.6.8
What you did
I tried to port my previous "remember me" cookie implementation (based on Cookie Component) to the new Cookie management.
My codebase is pretty simple:
I had 3 problems:
Cookie with redirect
If I set the cookie before a redirect, it doesn't set any cookie.
I tried to debug
ResponseEmitter.php
: in the functionemitHeaders()
it seems to resets the value of the variable$cookies
right after setting a header of type'Location: ...'.
For debug purpose I tried to temporarily remove the redirect like this:
and then
$cookies
correctly had the cookie i setted.Cookie with value of type array
After I removed the redirect, it gave me another error:
This is because it calls
Response->convertCookieToArray()
that doesn't convert values of typearray
tostring
.But I saw that
Cookie()
object can handle values of typearray
by using an internal variable$isExpanded
... is this correct?I expected that I could set a cookie with value of type
array
without the need to explicitly calljson_encode()
Encrypted Cookie
I don't know if I'm using it incorrectly, but
EncryptedCookieMiddleware
only decodes my cookie and doesn't encode it.This is my code (in
routes.php
):Maybe I didn't understand really well how middleware works, but there is only a
__invoke()
function that calls bothdecodeCookies()
in the request andencodeCookies()
in the response...But I set the cookie after that, right? So the cookie doesn't encode because the
__invoke()
function has already been called?Thank you
The text was updated successfully, but these errors were encountered: