     }
 }
 
-func getHeaderValue(_ k: String, d: Dictionary<NSObject, Any>) -> String? {
-//    if let v = d[k] as? String { // short path: attempt to get the header directly
-//        return v
-//    }
+func getHeaderValue(_ k: String, d: [String: String]?) -> String? {
+    guard let d = d else {
+        return nil
+    }
+    if let v = d[k] { // short path: attempt to get the header directly
+        return v
+    }
     let lkKey = k.lowercased() // long path: compare lowercase keys
     for (lk, lv) in d {
-        if lk is String {
-            let lks = lk as! String
-            if lks.lowercased() == lkKey {
-                if let lvs = lv as? String {
-                    return lvs
-                }
-            }
+        if lk.lowercased() == lkKey {
+            return lv
         }
     }
     return nil

        }
        
        func ver(key: String, completionFunc: @escaping (UInt64, Date, BRRemoteKVStoreError?) -> ()) {
            let req = NSMutableURLRequest(url: client.url("/kv/1/\(key)"))
            req.httpMethod = "HEAD"
            client.dataTaskWithRequest(req as URLRequest, authenticated: true, retryCount: 0) { (dat, resp, err) in
                if let err = err {
                    self.client.log("[KV] HEAD key=\(key) err=\(err)")
                    return completionFunc(0, Date(timeIntervalSince1970: 0), .unknown)

    return urlStr
}

func buildRequestSigningString(_ r: URLRequest) -> String {
    var parts = [
        r.httpMethod ?? "",
        "",
        getHeaderValue("content-type", d: r.allHTTPHeaderFields) ?? "",
        getHeaderValue("date", d: r.allHTTPHeaderFields) ?? "",
        buildURLResourceString(r.url)
    ]
    if let meth = r.httpMethod {
        switch meth {
        case "POST", "PUT", "PATCH":
            if let d = r.httpBody , d.count > 0 {
                let sha = (d as NSData).sha256()
                parts[1] = (NSData(uInt256: sha) as NSData).base58String()
            }
        default: break
        }
    }
    return parts.joined(separator: "\n")
}
