diff --git a/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift b/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift index de0d6cfec..127847955 100644 --- a/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift +++ b/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift @@ -37,35 +37,41 @@ internal class LokiFileServerProxy : LokiHTTPClient { // MARK: Proxying override internal func perform(_ request: TSRequest, withCompletionQueue queue: DispatchQueue = DispatchQueue.main) -> LokiAPI.RawResponsePromise { + let isLokiFileServer = server.contains("file.lokinet.org") || server.contains("file-dev.lokinet.org") + guard isLokiFileServer else { return super.perform(request, withCompletionQueue: queue) } // Don't proxy open group requests for now let uncheckedSymmetricKey = try? Curve25519.generateSharedSecret(fromPublicKey: LokiFileServerProxy.fileServerPublicKey, privateKey: keyPair.privateKey) guard let symmetricKey = uncheckedSymmetricKey else { return Promise(error: Error.symmetricKeyGenerationFailed) } - let headers = getCanonicalHeaders(for: request) + var headers = getCanonicalHeaders(for: request) + headers["Content-Type"] = "application/json" return LokiAPI.getRandomSnode().then { [server = self.server, keyPair = self.keyPair, httpSession = self.httpSession] proxy -> Promise in - let url = "\(proxy.address):\(proxy.port)/proxy" + let url = "\(proxy.address):\(proxy.port)/file_proxy" print("[Loki] Proxying request to \(server) through \(proxy).") guard let urlAsString = request.url?.absoluteString, let serverURLEndIndex = urlAsString.range(of: server)?.upperBound, serverURLEndIndex < urlAsString.endIndex else { throw Error.endpointParsingFailed } let endpointStartIndex = urlAsString.index(after: serverURLEndIndex) let endpoint = String(urlAsString[endpointStartIndex.. Promise in - print("[Loki] Proxy request failed with error: \(error.localizedDescription).") + print("[Loki] File server proxy request failed with error: \(error.localizedDescription).") throw HTTPError.from(error: error) ?? error } }