Skip to content

Add ETag support for local evaluation polling#66

Merged
dmarticus merged 3 commits intomainfrom
dmarticus/debug-autobump-ci
Feb 5, 2026
Merged

Add ETag support for local evaluation polling#66
dmarticus merged 3 commits intomainfrom
dmarticus/debug-autobump-ci

Conversation

@dmarticus
Copy link
Copy Markdown
Contributor

@dmarticus dmarticus commented Feb 5, 2026

Summary

Adds HTTP ETag/If-None-Match conditional request support to both FlagPoller (sync) and AsyncFlagPoller (async) polling loops. When flag definitions haven't changed, the server returns 304 Not Modified, saving bandwidth and processing.

Changes:

  • Track last_etag in the polling loop (local to the background thread/task)
  • Send If-None-Match header when an ETag is available from a previous response
  • Handle 304 Not Modified by skipping cache update (preserving existing flags)
  • Extract and store ETag from 200 responses only after successful JSON parse (prevents partial state)

Design notes:

  • load_flags() methods remain unconditional — they're for initial loads and manual refreshes
  • ETag state is local to the polling loop, not stored on the struct

Test plan

  • test_etag_sent_on_second_poll — verifies If-None-Match header is sent after receiving an ETag
  • test_304_preserves_cache — verifies 304 response preserves the existing cache
  • test_no_etag_from_server — verifies normal operation when server doesn't return ETags
  • All existing tests pass

The crates.io trusted publishing config expects release.yml, not
release.yaml. The earlier rename was backwards.
Add HTTP ETag/If-None-Match conditional request support to both
FlagPoller (sync) and AsyncFlagPoller (async) polling loops.
When flag definitions haven't changed, the server returns 304 Not
Modified, saving bandwidth and processing.

Changes:
- Track last_etag in the polling loop (not on struct, since it's
  only relevant to the background polling)
- Send If-None-Match header when etag is available
- Handle 304 Not Modified response by skipping cache update
- Extract and store ETag from 200 responses (only after successful
  JSON parse to avoid partial state)

Tests verify:
- If-None-Match header is sent after receiving an ETag
- 304 response preserves the existing cache
- Normal operation when server returns no ETag
Copy link
Copy Markdown

@haacked haacked left a comment

Choose a reason for hiding this comment

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

Nice! Happy to see this.

Some non-blocking suggestions.

}

#[cfg(feature = "async-client")]
#[tokio::test]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tests only cover AsyncFlagPoller. Consider adding equivalent tests for the sync FlagPoller to ensure parity - both implementations have the same ETag logic but only one is tested.

.path("/api/feature_flag/local_evaluation/")
.query_param("send_cohorts", "")
.matches(|req| {
// Match only if If-None-Match header exists
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The mock only verifies that the If-None-Match header exists, but doesn't verify its value is correct. Consider checking that the header value matches the ETag returned by the server:

.matches(|req| {
    req.headers.as_ref().is_some_and(|headers| {
        headers.iter().any(|(name, value)| {
            name.to_lowercase() == "if-none-match"
                && value.as_str() == "\"abc123\""
        })
    })
})

} else if response.status().is_success() {
// Extract ETag before consuming the response body
let new_etag = response
.headers()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor suggestion: Consider extracting ETag extraction into a shared helper function to reduce duplication with the async version:

fn extract_etag(headers: &HeaderMap) -> Option<String> {
    headers.get(ETAG)
        .and_then(|v| v.to_str().ok())
        .filter(|s| !s.is_empty())
        .map(|s| s.to_string())
}

- Extract ETag extraction into shared helper function to reduce duplication
- Update async tests to verify ETag value matches (not just header existence)
- Add equivalent sync FlagPoller tests for ETag behavior parity

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@dmarticus dmarticus merged commit 922a372 into main Feb 5, 2026
8 checks passed
@dmarticus dmarticus deleted the dmarticus/debug-autobump-ci branch February 5, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants