Skip to content
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

Allow Session scoped cookies. #1387

Merged
merged 6 commits into from Jan 12, 2022

Conversation

alex-oleshkevich
Copy link
Member

This PR changes the behavior of SessionMiddleware.
If the user sets max_age to None or 0 then a cookie will be Session-only and will be destroyed after closing the browser.

Copy link
Sponsor Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max_age type on the __init__ should be Optional[int] as it can receive None now.

docs/middleware.md Outdated Show resolved Hide resolved
alex-oleshkevich and others added 2 commits December 28, 2021 17:28
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
set_cookie = response.headers["set-cookie"]
assert "Max-Age" not in set_cookie

client.cookies.clear_session_cookies()
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to myself: use client.cookies.clear instead of client.cookies.clear_session_cookies on #1376

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? afaik this method will keep all other cookies except session-scoped.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, yeah... httpx doesn't have clear_session_cookies 😞

Copy link
Sponsor Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alex-oleshkevich :)

@Kludex Kludex merged commit a7c5a41 into encode:master Jan 12, 2022
@aminalaee aminalaee mentioned this pull request Jan 22, 2022
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants