import Foundation /// Request-local progress survives the lifetime and credential-renewal wrappers. final class UploadProgress: Sendable, Equatable { let report: @Sendable (Double) -> Void init(_ report: @escaping @Sendable (Double) -> Void) { self.report = report } static func == (lhs: UploadProgress, rhs: UploadProgress) -> Bool { lhs === rhs } } final class UploadDelegate: NSObject, URLSessionTaskDelegate, Sendable { let progress: UploadProgress init(_ progress: UploadProgress) { self.progress = progress } func urlSession(_ session: URLSession, task: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) { if totalBytesExpectedToSend > 0 { progress.report(min(1, Double(totalBytesSent) / Double(totalBytesExpectedToSend))) } } func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest) async -> URLRequest? { nil } }