Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Coder-Desktop/Coder-DesktopHelper/Manager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
}
Expand Down
7 changes: 7 additions & 0 deletions Coder-Desktop/VPNLib/Download.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import CoderSDK
import CryptoKit
import Foundation

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) }
)
}
Expand Down Expand Up @@ -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")
Expand Down