Skip to content

Commit

Permalink
Handle media upload headers
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Pex committed Sep 20, 2018
1 parent 1169253 commit c00882f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ChatSecure/Classes/Controllers/FileTransferManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,21 @@ public class FileTransferManager: NSObject, OTRServerCapabilitiesDelegate {
}
return
}
self.sessionManager.upload(outData, to: slot.putURL, method: .put)

// Pick optional headers from the slot and filter out any not allowed by
// XEP-0363 (https://xmpp.org/extensions/xep-0363.html#request)
let allowedHeaders = ["authorization", "cookie", "expires"]
var forwardedHeaders:HTTPHeaders = [:]
for (headerName, headerValue) in slot.putHeaders {
let name = headerName.replacingOccurrences(of: "\n", with: "").lowercased()
if allowedHeaders.contains(name) {
forwardedHeaders[name] = headerValue.replacingOccurrences(of: "\n", with: "")
}
}
forwardedHeaders["Content-Type"] = contentType
forwardedHeaders["Content-Length"] = "\(UInt(outData.count))"

self.sessionManager.upload(outData, to: slot.putURL, method: .put, headers: forwardedHeaders)
.validate()
.responseData(queue: self.callbackQueue) { response in
switch response.result {
Expand Down

0 comments on commit c00882f

Please sign in to comment.