diff --git a/Coder-Desktop/Coder-DesktopHelper/Manager.swift b/Coder-Desktop/Coder-DesktopHelper/Manager.swift index 778088d6..df79d8a1 100644 --- a/Coder-Desktop/Coder-DesktopHelper/Manager.swift +++ b/Coder-Desktop/Coder-DesktopHelper/Manager.swift @@ -41,7 +41,7 @@ actor Manager { "Failed to create directories for binary destination (\(dest)): \(error.localizedDescription)" ) } - let client = Client(url: cfg.serverUrl) + let client = Client(url: cfg.serverUrl, headers: cfg.literalHeaders) let buildInfo: BuildInfoResponse do { buildInfo = try await client.buildInfo() @@ -67,7 +67,8 @@ actor Manager { try await download( src: binaryPath, dest: dest, - urlSession: URLSession(configuration: sessionConfig) + urlSession: URLSession(configuration: sessionConfig), + headers: cfg.literalHeaders ) { progress in pushProgress(stage: .downloading, downloadProgress: progress) } diff --git a/Coder-Desktop/VPNLib/Download.swift b/Coder-Desktop/VPNLib/Download.swift index 37c53ec5..3441b982 100644 --- a/Coder-Desktop/VPNLib/Download.swift +++ b/Coder-Desktop/VPNLib/Download.swift @@ -1,3 +1,4 @@ +import CoderSDK import CryptoKit import Foundation @@ -5,12 +6,14 @@ public func download( src: URL, dest: URL, urlSession: URLSession, + headers: [HTTPHeader] = [], progressUpdates: (@Sendable (DownloadProgress) -> Void)? = nil ) async throws(DownloadError) { try await DownloadManager().download( src: src, dest: dest, urlSession: urlSession, + headers: headers, progressUpdates: progressUpdates.flatMap { throttle(interval: .milliseconds(10), $0) } ) } @@ -54,9 +57,13 @@ private final class DownloadManager: NSObject, @unchecked Sendable { src: URL, dest: URL, urlSession: URLSession, + headers: [HTTPHeader] = [], progressUpdates: (@Sendable (DownloadProgress) -> Void)? ) async throws(DownloadError) { var req = URLRequest(url: src) + for header in headers { + req.addValue(header.value, forHTTPHeaderField: header.name) + } if FileManager.default.fileExists(atPath: dest.path) { if let existingFileData = try? Data(contentsOf: dest, options: .mappedIfSafe) { req.setValue(etag(data: existingFileData), forHTTPHeaderField: "If-None-Match")