-
-
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
Wrong typing for expires in set_cookie #1878
Comments
I have the feeling we had this discussion before... Need to find where. 🤔 EDIT: Maybe not? |
See encode/starlette#1878 and the get_directories argument has changed, but we don't use it.
Hold on... Does the field EDIT: It is, I've checked on Google Chrome. It works as if it was seconds. Can someone double check this? |
Based on RFC-6265, we should send a string in cookie date format, as the OP said. We have even reference in code using starlette/starlette/middleware/sessions.py Lines 76 to 82 in 9a1e885
|
Questions:
|
|
It would be cool to understand why it works on Chrome 👀 |
PR welcome to change the type annotation, and add datetime, with conversion to the format mentioned. |
Hi, there! I created a pull request adding the changes requested by @Kludex . I made a point to follow them strictly. As I was working on the issue, two questions came to me, which I think it is good to discuss.
For these two reasons, I would suggest to add If we want to insist that Again, these are suggestions. This is the first time I have attempted to contribute to this project, so whatever you decide is best :) Thanks for making this beautiful framework. |
My best guess is that if you set is as int, it does not work and you get a
session cookie. If you don’t use mypy (I did, but it never raised an error
until now, strange but off-topic) you just need to pass it the right date
format (which I did). I think optional date str would be perfect.
On Fri, 30 Sep 2022 at 21:51, Marcelo Trylesinski ***@***.***> wrote:
Questions:
1. Why the current expires works?
2. Should we change the type from Optional[int] (Union[int, None]) to Union[int,
str, None]?
3. Should we accept datetime instead, and let Starlette format as cookie
date <https://www.rfc-editor.org/rfc/rfc6265#section-5.1.1>?
—
Reply to this email directly, view it on GitHub
<#1878 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANPEPN43EFTVSFLL4WZT2DWA5ADRANCNFSM6AAAAAAQZYGOLA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Maarten Breddels
Software engineer / consultant / data scientist
Python / C++ / Javascript / Jupyter
www.maartenbreddels.com / vaex.io
***@***.*** +31 6 2464 0838 <+31+6+24640838>
[image: Twitter] <https://twitter.com/maartenbreddels>[image: Github]
<https://github.com/maartenbreddels>[image: LinkedIn]
<https://linkedin.com/in/maartenbreddels>[image: Skype]
|
Which frameworks, servers and browsers? |
Php, for example, uses seconds from epoch, https://www.php.net/manual/en/function.setcookie.php I thought I saw more examples, but maybe it was just PHP :) |
@maartenbreddels if we just accept |
I would also support string, unless I’m 100+% sure with datetime we can cover the whole spec (which in reality is unlikely). The risk of adding no escape hatch is just too high in practice. So I’d say datetime | str to be safe. |
Why is it unlikely? |
I think the type for
starlette/starlette/responses.py
Line 108 in 55b0cbd
This should be a date according to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
So I think a better type is
Optional[str]
, or Optional[str | datetime] and provide the right formatting.The text was updated successfully, but these errors were encountered: