Skip to content
5 changes: 4 additions & 1 deletion Sources/AsyncHTTPClient/FileDownloadDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public final class FileDownloadDelegate: HTTPClientResponseDelegate {
public struct Progress: Sendable {
public var totalBytes: Int?
public var receivedBytes: Int
public var head: HTTPResponseHead!
}

private var progress = Progress(totalBytes: nil, receivedBytes: 0)
private var progress = Progress(totalBytes: nil, receivedBytes: 0, head: nil)

public typealias Response = Progress

Expand Down Expand Up @@ -135,6 +136,8 @@ public final class FileDownloadDelegate: HTTPClientResponseDelegate {
) -> EventLoopFuture<Void> {
self.reportHead?(task, head)

self.progress.head = head

if let totalBytesString = head.headers.first(name: "Content-Length"),
let totalBytes = Int(totalBytesString)
{
Expand Down