Skip to content

Allow Session scoped cookies.#1387

Merged
Kludex merged 6 commits intoKludex:masterfrom
alex-oleshkevich:session-scoped-cookies
Jan 12, 2022
Merged

Allow Session scoped cookies.#1387
Kludex merged 6 commits intoKludex:masterfrom
alex-oleshkevich:session-scoped-cookies

Conversation

@alex-oleshkevich
Copy link
Contributor

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
Owner

@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.

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
Owner

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
Contributor 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
Owner

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
Owner

@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 Kludex: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.

2 participants