Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions flex-api-ios-sdk/FlexTokens Feature/HttpResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ struct HttpResponse: Equatable {
static func == (lhs: HttpResponse, rhs: HttpResponse) -> Bool {
return lhs.status == rhs.status && lhs.body == rhs.body
}

let status: Int
let body: String?
let headers: [AnyHashable: Any]?
Expand All @@ -21,16 +20,18 @@ struct HttpResponse: Equatable {
self.body = body
self.headers = headers
}

func isValidResponse() -> Bool {
(200...299).contains(self.status)
}

func getValue(for key: String) -> String? {
if let field = self.headers?[key.lowercased()] as? String {
return field
}

return nil
// attempt to get header value using exact key
if let field = self.headers?[key] as? String {
return field
}

// Then try case-insensitive match if needed
return self.headers?.first(where: {
($0.key as? String)?.lowercased() == key.lowercased()
})?.value as? String
}
}