-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes type inference issue, that caused problem with non-200 status code responses. venmo#75
- Loading branch information
Showing
3 changed files
with
16 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,14 @@ | ||
import Foundation | ||
|
||
// There isn't a mutable HTTPURLResponse, so we have to make our own. | ||
class HTTPURLResponse: Foundation.HTTPURLResponse { | ||
|
||
// MARK: - Properties | ||
|
||
private var _url: URL? | ||
override var url: URL? { | ||
get { | ||
return _url ?? super.url | ||
} | ||
|
||
set { | ||
_url = newValue | ||
} | ||
} | ||
|
||
private var _statusCode: Int? | ||
override var statusCode: Int { | ||
get { | ||
return _statusCode ?? super.statusCode | ||
} | ||
|
||
set { | ||
_statusCode = newValue | ||
} | ||
} | ||
|
||
private var _allHeaderFields: [AnyHashable: Any]? | ||
override var allHeaderFields: [AnyHashable: Any] { | ||
get { | ||
return _allHeaderFields ?? super.allHeaderFields | ||
} | ||
|
||
set { | ||
_allHeaderFields = newValue | ||
} | ||
} | ||
} | ||
|
||
|
||
extension HTTPURLResponse { | ||
convenience init(dictionary: [String: Any]) { | ||
let url = URL(string: dictionary["url"] as! String)! | ||
|
||
self.init(url: url, mimeType: nil, expectedContentLength: 0, textEncodingName: nil) | ||
convenience init?(dictionary: [String: Any]) { | ||
guard let urlString = dictionary["url"] as? String, | ||
let url = URL(string: urlString), | ||
let statusCode = dictionary["status"] as? Int | ||
else { return nil } | ||
|
||
if let headers = dictionary["headers"] as? [String: String] { | ||
allHeaderFields = headers | ||
} | ||
|
||
if let status = dictionary["status"] as? Int { | ||
statusCode = status | ||
} | ||
let headers = dictionary["headers"] as? [String: String] | ||
self.init(url: url, statusCode: statusCode, httpVersion: nil, headerFields: headers) | ||
} | ||
} | ||
|
This file contains 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