Make HTTPConditionalGetInfo serializable via a dictionary.
This commit is contained in:
parent
2978d4420b
commit
8d9c9217dc
|
@ -8,30 +8,55 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
public struct HTTPConditionalGetInfo: Codable {
|
||||
public struct HTTPConditionalGetInfo {
|
||||
|
||||
public let lastModified: String?
|
||||
public let etag: String?
|
||||
|
||||
public var isEmpty: Bool {
|
||||
get {
|
||||
return lastModified == nil && etag == nil
|
||||
}
|
||||
}
|
||||
|
||||
public init(lastModified: String?, etag: String?) {
|
||||
|
||||
public init?(lastModified: String?, etag: String?) {
|
||||
|
||||
if lastModified == nil && etag == nil {
|
||||
return nil
|
||||
}
|
||||
self.lastModified = lastModified
|
||||
self.etag = etag
|
||||
}
|
||||
|
||||
public init(urlResponse: HTTPURLResponse) {
|
||||
public init?(urlResponse: HTTPURLResponse) {
|
||||
|
||||
let lastModified = urlResponse.valueForHTTPHeaderField(HTTPResponseHeader.lastModified)
|
||||
let etag = urlResponse.valueForHTTPHeaderField(HTTPResponseHeader.etag)
|
||||
|
||||
self.init(lastModified: lastModified, etag: etag)
|
||||
}
|
||||
|
||||
|
||||
public var dictionary: [String: String]? {
|
||||
get {
|
||||
if lastModified == nil && etag == nil {
|
||||
return nil
|
||||
}
|
||||
var d = [String: String]()
|
||||
if let lastModified = lastModified {
|
||||
d[HTTPResponseHeader.lastModified] = lastModified
|
||||
}
|
||||
if let etag = etag {
|
||||
d[HTTPResponseHeader.etag] = etag
|
||||
}
|
||||
return d
|
||||
}
|
||||
}
|
||||
|
||||
public init?(dictionary: [String: String]) {
|
||||
|
||||
self.init(lastModified: dictionary[HTTPResponseHeader.lastModified], etag: dictionary[HTTPResponseHeader.etag])
|
||||
}
|
||||
|
||||
public func addRequestHeadersToURLRequest(_ urlRequest: NSMutableURLRequest) {
|
||||
|
||||
if let lastModified = lastModified {
|
||||
|
|
Loading…
Reference in New Issue