Skip to content

Allow HTTPFetcher to pass through 304 responses#4120

Draft
sonnyb9 wants to merge 1 commit intoMagicMirrorOrg:masterfrom
sonnyb9:codex/httpfetcher-304-pass-through
Draft

Allow HTTPFetcher to pass through 304 responses#4120
sonnyb9 wants to merge 1 commit intoMagicMirrorOrg:masterfrom
sonnyb9:codex/httpfetcher-304-pass-through

Conversation

@sonnyb9
Copy link
Copy Markdown

@sonnyb9 sonnyb9 commented Apr 24, 2026

Summary

This updates js/http_fetcher.js so HTTP 304 Not Modified responses are emitted through the normal response event instead of being treated as errors.

That aligns the core fetcher with the built-in yr weather provider in v2.35.0, which already includes explicit logic to handle 304 and reuse cached data.

Closes #4119.

Root cause

HTTPFetcher currently treats all non-OK responses as errors. Since 304 is not an OK response, it never reaches providers listening on the response event.

At the same time, defaultmodules/weather/providers/yr.js expects to receive 304 and handle it by reusing cached data.

What changed

  • special-case HTTP 304 in HTTPFetcher
  • emit 304 through the normal response event
  • preserve the existing error path for other non-OK statuses

Validation

  • confirmed defaultmodules/weather/providers/yr.js already expects response.status === 304
  • compared the unpatched v2.35.0 HTTPFetcher behavior to the provider logic
  • ran node --check js/http_fetcher.js

@rejas
Copy link
Copy Markdown
Collaborator

rejas commented Apr 24, 2026

Please base your PR against the develop branch

Comment thread js/http_fetcher.js
if (response.status === 304) {
// Allow providers with cache-aware handling to reuse prior data.
this.emit("response", response);
} else if (!response.ok) {
Copy link
Copy Markdown
Collaborator

@KristjanESPERANTO KristjanESPERANTO Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would skip the error count reset for 304s - but a 304 means the server is healthy, so serverErrorCount/networkErrorCount should still be cleared.

This would fix that:

			const isSuccessfulResponse = response.ok || response.status === 304;

			if (!isSuccessfulResponse) {

The reset would happen in the else branch.

Additionally, we could even reverse the if condition to handle the happy path first, which would make the code even easier to understand. That wouldn't strictly fall within the scope of this PR, but it would be a small refactoring that I would consider as a minor acceptable tweak.

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.

HTTPFetcher drops HTTP 304 responses needed by yr provider cache handling

3 participants