@@ -19,14 +19,22 @@ import NIOPosix
1919/// Handles a streaming download to a given file path, allowing headers and progress to be reported.
2020public final class FileDownloadDelegate : HTTPClientResponseDelegate {
2121 /// The response type for this delegate: the total count of bytes as reported by the response
22- /// "Content-Length" header (if available) and the count of bytes downloaded.
22+ /// "Content-Length" header (if available), the count of bytes downloaded, and the
23+ /// response head.
2324 public struct Progress : Sendable {
2425 public var totalBytes : Int ?
2526 public var receivedBytes : Int
26- public var head : HTTPResponseHead !
27+ public var head : HTTPResponseHead
2728 }
2829
29- private var progress = Progress ( totalBytes: nil , receivedBytes: 0 , head: nil )
30+ private var progress = Progress (
31+ totalBytes: nil ,
32+ receivedBytes: 0 ,
33+ head: . init(
34+ version: . init( major: 0 , minor: 0 ) ,
35+ status: . init( statusCode: 0 )
36+ )
37+ )
3038
3139 public typealias Response = Progress
3240
@@ -134,10 +142,10 @@ public final class FileDownloadDelegate: HTTPClientResponseDelegate {
134142 task: HTTPClient . Task < Response > ,
135143 _ head: HTTPResponseHead
136144 ) -> EventLoopFuture < Void > {
137- self . reportHead ? ( task, head)
138-
139145 self . progress. head = head
140146
147+ self . reportHead ? ( task, head)
148+
141149 if let totalBytesString = head. headers. first ( name: " Content-Length " ) ,
142150 let totalBytes = Int ( totalBytesString)
143151 {
0 commit comments