@@ -19,14 +19,22 @@ import NIOPosix
19
19
/// Handles a streaming download to a given file path, allowing headers and progress to be reported.
20
20
public final class FileDownloadDelegate : HTTPClientResponseDelegate {
21
21
/// 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.
23
24
public struct Progress : Sendable {
24
25
public var totalBytes : Int ?
25
26
public var receivedBytes : Int
26
- public var head : HTTPResponseHead !
27
+ public var head : HTTPResponseHead
27
28
}
28
29
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
+ )
30
38
31
39
public typealias Response = Progress
32
40
@@ -134,10 +142,10 @@ public final class FileDownloadDelegate: HTTPClientResponseDelegate {
134
142
task: HTTPClient . Task < Response > ,
135
143
_ head: HTTPResponseHead
136
144
) -> EventLoopFuture < Void > {
137
- self . reportHead ? ( task, head)
138
-
139
145
self . progress. head = head
140
146
147
+ self . reportHead ? ( task, head)
148
+
141
149
if let totalBytesString = head. headers. first ( name: " Content-Length " ) ,
142
150
let totalBytes = Int ( totalBytesString)
143
151
{
0 commit comments