From 93c455fa41296d3d4b4c69294e77ed778847e48f Mon Sep 17 00:00:00 2001 From: Pushkar N Kulkarni Date: Wed, 31 Aug 2016 23:52:44 +0530 Subject: [PATCH] Swift 3 API parity: Change type of HTTPURLResponse.allHeaderFields to match Darwin --- Foundation/NSURLResponse.swift | 5 +++-- TestFoundation/TestNSURLResponse.swift | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Foundation/NSURLResponse.swift b/Foundation/NSURLResponse.swift index 1c691f0f39..e74f9f1e38 100644 --- a/Foundation/NSURLResponse.swift +++ b/Foundation/NSURLResponse.swift @@ -154,7 +154,7 @@ open class HTTPURLResponse : URLResponse { /// /// - Important: This is an *experimental* change from the /// `[NSObject: AnyObject]` type that Darwin Foundation uses. - public let allHeaderFields: [String: String] + public let allHeaderFields: [AnyHashable : Any] /// Convenience method which returns a localized string /// corresponding to the status code for this response. @@ -233,7 +233,8 @@ open class HTTPURLResponse : URLResponse { /// This property is intended to produce readable output. override open var description: String { var result = "<\(type(of: self)) \(Unmanaged.passUnretained(self).toOpaque())> { URL: \(url!.absoluteString) }{ status: \(statusCode), headers {\n" - for(key, value) in allHeaderFields { + for(aKey, aValue) in allHeaderFields { + guard let key = aKey as? String, let value = aValue as? String else { continue } //shouldn't typically fail here if((key.lowercased() == "content-disposition" && suggestedFilename != "Unknown") || key.lowercased() == "content-type") { result += " \"\(key)\" = \"\(value)\";\n" } else { diff --git a/TestFoundation/TestNSURLResponse.swift b/TestFoundation/TestNSURLResponse.swift index 9db8b75447..9e67ffae91 100644 --- a/TestFoundation/TestNSURLResponse.swift +++ b/TestFoundation/TestNSURLResponse.swift @@ -156,8 +156,8 @@ class TestNSHTTPURLResponse : XCTestCase { let f = ["A": "1", "B": "2"] let sut = HTTPURLResponse(url: url, statusCode: 200, httpVersion: "HTTP/1.1", headerFields: f) XCTAssertEqual(sut?.allHeaderFields.count, 2) - XCTAssertEqual(sut?.allHeaderFields["A"], "1") - XCTAssertEqual(sut?.allHeaderFields["B"], "2") + XCTAssertEqual(sut?.allHeaderFields["A"] as! String, "1") + XCTAssertEqual(sut?.allHeaderFields["B"] as! String, "2") } // Note that the message content length is different from the message