Add ETag support for local evaluation polling#66
Merged
Conversation
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
haacked
approved these changes
Feb 5, 2026
haacked
left a comment
There was a problem hiding this comment.
Nice! Happy to see this.
Some non-blocking suggestions.
| } | ||
|
|
||
| #[cfg(feature = "async-client")] | ||
| #[tokio::test] |
There was a problem hiding this comment.
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.
tests/test_local_evaluation.rs
Outdated
| .path("/api/feature_flag/local_evaluation/") | ||
| .query_param("send_cohorts", "") | ||
| .matches(|req| { | ||
| // Match only if If-None-Match header exists |
There was a problem hiding this comment.
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\""
})
})
})
src/local_evaluation.rs
Outdated
| } else if response.status().is_success() { | ||
| // Extract ETag before consuming the response body | ||
| let new_etag = response | ||
| .headers() |
There was a problem hiding this comment.
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>
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.
Summary
Adds HTTP ETag/If-None-Match conditional request support to both
FlagPoller(sync) andAsyncFlagPoller(async) polling loops. When flag definitions haven't changed, the server returns 304 Not Modified, saving bandwidth and processing.Changes:
last_etagin the polling loop (local to the background thread/task)If-None-Matchheader when an ETag is available from a previous responseDesign notes:
load_flags()methods remain unconditional — they're for initial loads and manual refreshesTest plan
test_etag_sent_on_second_poll— verifiesIf-None-Matchheader is sent after receiving an ETagtest_304_preserves_cache— verifies 304 response preserves the existing cachetest_no_etag_from_server— verifies normal operation when server doesn't return ETags