Skip to content

Commit 82e74b9

Browse files
committed
init head with bogus data
it will never be seen by the library user with this data since `didReceiveHead(...)` is called before we report progress or finalize
1 parent 6edf1e7 commit 82e74b9

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Sources/AsyncHTTPClient/FileDownloadDelegate.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,22 @@ import NIOPosix
1919
/// Handles a streaming download to a given file path, allowing headers and progress to be reported.
2020
public 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

Comments
 (0)