Skip to content

fix(poller): perform case-insensitive lookup for etag header and upda… - #137

Merged
sighphyre merged 1 commit into
Unleash:mainfrom
jose-gil:fix/etag-case-insensitive
Aug 14, 2026
Merged

fix(poller): perform case-insensitive lookup for etag header and upda…#137
sighphyre merged 1 commit into
Unleash:mainfrom
jose-gil:fix/etag-case-insensitive

Conversation

@jose-gil

@jose-gil jose-gil commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

#136

Describe the bug

In Poller.swift, the ETag header was accessed directly from HTTPURLResponse.allHeaderFielsusing key indexing: if let newTag = httpResponse.allHeaderFields["Etag"] as? string.

Becase allHeaderFields returns 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"] returns nil. 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 testLowerCaseEtagResponseHeader appeared to pass becase it instantiate HTTPURLResponse directly via: HTTPURLResponse(url: url, statusCode: 200, httpVersion: nil, headerFields: ["etag": "..."]).

Apple's HTTPURLResponse initializer 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 on allHeaderFields["Etag"] is case-sensitive.

Proposed Fix

@sighphyre sighphyre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cheers, thanks for fixing this. Looks small and safe

@github-project-automation github-project-automation Bot moved this from New to Approved PRs in Issues and PRs Aug 14, 2026
@sighphyre
sighphyre merged commit d55a45e into Unleash:main Aug 14, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Issues and PRs Aug 14, 2026
@jose-gil
jose-gil deleted the fix/etag-case-insensitive branch August 30, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants