fix(poller): perform case-insensitive lookup for etag header and upda… - #137
Merged
Merged
Conversation
sighphyre
approved these changes
Aug 14, 2026
sighphyre
left a comment
Member
There was a problem hiding this comment.
Cheers, thanks for fixing this. Looks small and safe
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.
#136
Describe the bug
In
Poller.swift, the ETag header was accessed directly fromHTTPURLResponse.allHeaderFielsusingkey indexing:if let newTag = httpResponse.allHeaderFields["Etag"] as? string.Becase
allHeaderFieldsreturns a standard dictionary ([AnyHashable: Any]), indexing it with["Etag"]performs a case-sensitive lookup. This is also confirmed in the documentation in the discussion section (https://developer.apple.com/documentation/foundation/httpurlresponse/allheaderfields).About the changes
According to the HTTP specification (RFC 7230), HTTP header field names are case-insensitive. In production environments-especially over HTTP/2 or behind proxies/CDNs that lowercase header names (e.g., etag instead of Etag)
httpResponse.allHeaderFields["Etag"]returnsnil. As a result, the SDK fails to capture and store the updated etag, preventing If-None-Match caching from working properly.Why existing unit tests missed this bug
The existing unit test
testLowerCaseEtagResponseHeaderappeared to pass becase it instantiateHTTPURLResponsedirectly via:HTTPURLResponse(url: url, statusCode: 200, httpVersion: nil, headerFields: ["etag": "..."]).Apple's
HTTPURLResponseinitializer canonicalizes dictionary keys in headerFields upon creation. This masked the bug in unit testing becase the mock response keys were normalized, hiding the fact that direct dictionary subscribing onallHeaderFields["Etag"]is case-sensitive.Proposed Fix
Use
valuer(forHTTPHeaderFields:)inPoller.swift:Replace direct dictionary lookup with Foundation's standard case-insensitive header lookup method (https://developer.apple.com/documentation/foundation/httpurlresponse/value(forhttpheaderfield:)).
Fix Unit Tests (
PollerTests.swift):Subclass/mock
HTTPURLResponsein test suites so header keys retain their exact case without Foundation's automatic key normalization.