Converting to Swift 3 I noticed a strange bug occur reading a header field from HTTPURLResponse.
let id = httpResponse.allHeaderFields["eTag"] as? String
Update: this is a known issue.
allHeaderFields should return a case-insensitive dictionary because that is what the HTTP spec requires. Looks like a Swift error, I would file a radar or a bug report on .
Here is some sample code that reproduces the issue simply:
let headerFields = ["ETag" : "12345678"] let url = URL(string: "http://www.example.com")! let response = HTTPURLResponse(url: url, statusCode: 200, httpVersion: "HTTP/1.1", headerFields: headerFields)! response.allHeaderFields["eTaG"] // nil (incorrect) headerFields["eTaG"] // nil (correct)
(Adapted from this Gist from Cédric Luthi.)