Skip to content

fix: preserve caller headers across 302 re-login retry in _get_url#223

Draft
bluetoothbot wants to merge 2 commits into
hvaclibs:masterfrom
bluetoothbot:koan/get-url-preserve-headers-on-relogin
Draft

fix: preserve caller headers across 302 re-login retry in _get_url#223
bluetoothbot wants to merge 2 commits into
hvaclibs:masterfrom
bluetoothbot:koan/get-url-preserve-headers-on-relogin

Conversation

@bluetoothbot

@bluetoothbot bluetoothbot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

What: Preserve the caller's request headers across the 302 re-login retry in NexiaHome._get_url.

Why: _update() sends an If-None-Match conditional-request header so an unchanged house returns a cheap 304. On a 302 (expired session → redirect to login), _get_url re-authenticates and recurses — but it called self._get_url(request_url) without the headers argument, silently dropping If-None-Match. So the first poll after every session expiry refetched the full house JSON instead of getting a 304. post_url/put_url already re-pass their payload on retry; the GET path was the asymmetric outlier.

How: Thread headers into 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 carries If-None-Match; fails before the fix with KeyError). 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

bluetoothbot and others added 2 commits June 23, 2026 05:45
_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

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

1 participant