Skip to content

Allow Session scoped cookies. - #1387

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

Kludex merged 6 commits into
Kludex:masterfrom
alex-oleshkevich:session-scoped-cookies

Conversation

@alex-oleshkevich

Copy link
Copy Markdown
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.

@Kludex Kludex left a comment

Copy link
Copy Markdown
Owner

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.

Comment thread docs/middleware.md Outdated
set_cookie = response.headers["set-cookie"]
assert "Max-Age" not in set_cookie

client.cookies.clear_session_cookies()

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 馃槥

@Kludex Kludex left a comment

Copy link
Copy Markdown
Owner

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