Skip to content

Commit

Permalink
Merge pull request #16 from frankct310/issue-14a
Browse files Browse the repository at this point in the history
Fix for issue #14: location header not always capitalized by UPnP devices
  • Loading branch information
happycodelucky authored Jan 16, 2019
2 parents 7dd4977 + 8d97ff8 commit 1a7fe43
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion SwiftSSDP/SSDPResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ public enum SSDPMessage {
case notify
}

/// Case insensitive indexing for things like location etc
extension Dictionary where Key == String {

subscript(caseInsensitive key: Key) -> Value? {
get {
if let k = keys.first(where: { $0.caseInsensitiveCompare(key) == .orderedSame }) {
return self[k]
}
return nil
}
set {
if let k = keys.first(where: { $0.caseInsensitiveCompare(key) == .orderedSame }) {
self[k] = newValue
} else {
self[key] = newValue
}
}
}
}
//
// MARK: -
//
Expand Down Expand Up @@ -203,7 +222,7 @@ extension SSDPMSearchResponse {
mutableHeaders.removeValue(forKey: SSDPHeaderKeys.ext)

// LOCATION
guard let location = headers[SSDPHeaderKeys.location], let locationUrl = URL(string: location) else {
guard let location = headers[caseInsensitive:SSDPHeaderKeys.location], let locationUrl = URL(string: location) else {
return nil
}
self.location = locationUrl
Expand Down

0 comments on commit 1a7fe43

Please sign in to comment.