fix: preserve auth cookies across Google redirects#274
fix: preserve auth cookies across Google redirects#274voidborne-d wants to merge 1 commit intoteng-lin:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe PR fixes an authentication bug where raw HTTP Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request refactors the httpx client to use the built-in cookie jar instead of manual Cookie headers and expands the allowed cookie domains to include accounts.google.com. Review feedback suggests ensuring that session cookies updated by the server are synchronized back to the local state to maintain session continuity and recommends adopting granular timeouts for better network resilience.
| self._http_client.cookies.clear() | ||
| self._http_client.cookies.update(self.auth.cookies) | ||
|
|
There was a problem hiding this comment.
Clearing the cookie jar here will discard any session cookies or updates received from the server during previous requests (including the refresh request itself) that haven't been manually synced back to self.auth.cookies. Since self.auth.cookies is a simple dictionary, it doesn't automatically track changes in the httpx cookie jar. To maintain session continuity, consider updating self.auth.cookies from the jar before resetting, or simply updating the jar without clearing it.
| self._http_client.cookies.clear() | |
| self._http_client.cookies.update(self.auth.cookies) | |
| self.auth.cookies.update(self._http_client.cookies) | |
| self._http_client.cookies.clear() | |
| self._http_client.cookies.update(self.auth.cookies) |
| async with httpx.AsyncClient(cookies=cookies, follow_redirects=True, timeout=30.0) as client: | ||
| response = await client.get("https://notebooklm.google.com/") | ||
| response.raise_for_status() | ||
|
|
There was a problem hiding this comment.
The httpx.AsyncClient correctly handles cookies during redirects, but any new cookies set by the server are currently lost when the client is closed. Updating the cookies dictionary ensures these updates are preserved. Additionally, when using httpx.AsyncClient, configure granular timeouts with a shorter connect timeout and a longer read timeout to improve network resilience.
| async with httpx.AsyncClient(cookies=cookies, follow_redirects=True, timeout=30.0) as client: | |
| response = await client.get("https://notebooklm.google.com/") | |
| response.raise_for_status() | |
| async with httpx.AsyncClient(cookies=cookies, follow_redirects=True, timeout=httpx.Timeout(10.0, read=60.0)) as client: | |
| response = await client.get("https://notebooklm.google.com/") | |
| response.raise_for_status() | |
| cookies.update(client.cookies) |
References
- When using httpx.AsyncClient, configure granular timeouts with a shorter connect timeout and a longer read timeout (e.g., httpx.Timeout(10.0, read=60.0)) to improve network resilience.
Summary
Cookieheaders to httpx cookie jarsaccounts.google.comcookies when loading storage state so Google auth redirects stay authenticatedTesting
Closes #273
Summary by CodeRabbit
Bug Fixes
Tests