Skip to content

Commit

Permalink
Fix for issue #14: location header not always capitalized by UPnP dev…
Browse files Browse the repository at this point in the history
…ices
  • Loading branch information
FrankC committed Nov 13, 2018
1 parent 7dd4977 commit 8d97ff8
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 8d97ff8

Please sign in to comment.