fix: preserve caller headers across 302 re-login retry in _get_url#223
Draft
bluetoothbot wants to merge 2 commits into
Draft
fix: preserve caller headers across 302 re-login retry in _get_url#223bluetoothbot wants to merge 2 commits into
bluetoothbot wants to merge 2 commits into
Conversation
_get_url dropped the caller's headers when recursing after a 302 re-login, unlike post_url/put_url which re-pass their payload. This silently discarded the If-None-Match conditional-request header that _update() sends, so the first poll after every session expiry refetched the full house JSON instead of getting a cheap 304.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What: Preserve the caller's request headers across the 302 re-login retry in
NexiaHome._get_url.Why:
_update()sends anIf-None-Matchconditional-request header so an unchanged house returns a cheap304. On a302(expired session → redirect to login),_get_urlre-authenticates and recurses — but it calledself._get_url(request_url)without theheadersargument, silently droppingIf-None-Match. So the first poll after every session expiry refetched the full house JSON instead of getting a 304.post_url/put_urlalready re-pass their payload on retry; the GET path was the asymmetric outlier.How: Thread
headersinto the recursive call._api_key_headers()is re-applied unconditionally inside_get_url, so only the caller-supplied conditional header needed preserving.Testing: Added
test_get_url_preserves_headers_on_relogin_retry(asserts the retry GET carriesIf-None-Match; fails before the fix withKeyError). Full suite green (58 passed, 1 skipped), ruff + mypy clean.Quality Report
Changes: 2 files changed, 29 insertions(+), 1 deletion(-)
Code scan: clean
Tests: passed (58 passed)
Branch hygiene: clean
Generated by Kōan