-
-
Notifications
You must be signed in to change notification settings - Fork 933
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
Instruct browser to remove cookies #563
Conversation
The previous behavior of Response's unset_cookie function was just to delete the given name from the SimpleCookie object if it existed. However, this causes a problem in that the browser is not told to remove the cookie on its side, causing all future Request objects to still contain the cookie that was supposed to have been unset/removed. This change causes the Response object to actually set the expires token for the cookie that is being unset to a point in the past, causing the browser to immediately remove the now-expired cookie, which will remove the cookie from future Request objects.
Docstring now mentions that the browser's copy of a cookie will be expired when using the unset_cookie method.
@kgriffs The docstring has been expanded. Let me know if the explanation is satisfactory. |
del self._cookies[name] | ||
if self._cookies is None: | ||
self._cookies = SimpleCookie() | ||
if name not in self._cookies: |
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.
Would it make sense to always set the value to the empty string, even if it was set elsewhere in the app to some value?
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.
That actually does make sense. I'll make that change.
Looks good, thanks! |
Instead of having a branch checking for if the cookie already exists, just wipe out the existing value with the blank string. The intention is to remove the cookie, so there's no reason to preserve a previous value.
As per how comments are handled for Falcon: a newline is before the large comment and the "NOTE" tag has been added.
@Freezerburn Looks good. As a final step in preparation for merging, could you please rebase on master and squash down to a single commit, formatted according to our style guide? Thanks! |
@Freezerburn I think this is ready to go, but it needs to be rebased first. |
Manually rebased and resubmitted as #634 |
[merged via #634] |
fix: Cookies not being removed from browser
The previous behavior of Response's unset_cookie function was just to delete the given name from the SimpleCookie object if it existed. However, this causes a problem in that the browser is not told to remove the cookie on its side, causing all future Request objects to still contain the cookie that was supposed to have been unset/removed. This change causes the Response object to actually set the expires token for the cookie that is being unset to a point in the past, causing the browser to immediately remove the now-expired cookie, which will remove the cookie from future Request objects.