Regression: HTTPURLResponse allHeaderFields is now case-sensitive
| Originator: | alex.sporn | ||
| Number: | rdar://27925651 | Date Originated: | 19-Aug-2016 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Version 8.0 beta 6 (8S201h) |
| Classification: | Serious Bug | Reproducible: | Always |
Summary:
HTTPURLResponse normalizes header names following RFC 2616 as described in https://developer.apple.com/reference/foundation/httpurlresponse/1417930-allheaderfields
Access to these header values is case-insensitive as described in the documentation. This is broken in the latest Xcode8 beta6. The access is now case-sensitive.
Additionally the "ETag" header name is normalized to "Etag" instead of "ETag" as described in RFC 2616
This works correctly on Xcode8 beta4
Steps to Reproduce:
Run following Swift code:
let url = URL(string: "http://www.apple.com")!
let headers = [
"ETag" : "123456",
"content-type": "application/json",
]
let urlResponse = HTTPURLResponse(url: url,
statusCode: 200,
httpVersion: nil,
headerFields: headers)
print("ETag: \(urlResponse?.allHeaderFields["ETag"])")
print("Etag: \(urlResponse?.allHeaderFields["Etag"])")
print("ETAG: \(urlResponse?.allHeaderFields["ETAG"])")
print("etag: \(urlResponse?.allHeaderFields["etag"])")
print("content-type: \(urlResponse?.allHeaderFields["content-type"])")
print("Content-Type: \(urlResponse?.allHeaderFields["Content-Type"])")
print("CONTENT-TYPE: \(urlResponse?.allHeaderFields["CONTENT-TYPE"])")
Same code in Objective-C works as expected:
NSURL *url = [[NSURL alloc] initWithString:@"http://www.apple.com"];
NSDictionary *headers = @{
@"ETag": @"123456",
@"content-type": @"application/json",
};
NSURL *url = [[NSURL alloc] initWithString:@"http://www.apple.com"];
NSDictionary *headers = @{
@"ETag": @"123456",
@"content-type": @"application/json",
};
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:url
statusCode:200
HTTPVersion:nil
headerFields:headers];
NSLog(@"Headers: %@", response.allHeaderFields);
NSLog(@"ETag: %@", response.allHeaderFields[@"ETag"]);
NSLog(@"Etag: %@", response.allHeaderFields[@"Etag"]);
NSLog(@"etag: %@", response.allHeaderFields[@"etag"]);
NSLog(@"ETAG: %@", response.allHeaderFields[@"ETAG"]);
NSLog(@"content-type: %@", response.allHeaderFields[@"content-type"]);
NSLog(@"Content-Type: %@", response.allHeaderFields[@"Content-Type"]);
NSLog(@"CONTENT-TYPE: %@", response.allHeaderFields[@"CONTENT-TYPE"]);
Expected Results:
Headers: Optional([AnyHashable("Content-Type"): application/json, AnyHashable("Etag"): 123456])
ETag: Optional(123456)
Etag: Optional(123456)
ETAG: Optional(123456)
etag: Optional(123456)
content-type: Optional(application/json)
Content-Type: Optional(application/json)
CONTENT-TYPE: Optional(application/json)
Actual Results:
Headers: Optional([AnyHashable("Content-Type"): application/json, AnyHashable("Etag"): 123456])
ETag: nil
Etag: Optional(123456)
ETAG: nil
etag: nil
content-type: nil
Content-Type: Optional(application/json)
CONTENT-TYPE: nil
Version:
Version 8.0 beta 6 (8S201h)
Notes:
Configuration:
Attachments:
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Swift bug report: https://bugs.swift.org/browse/SR-2429