Skip to content

FileDownloadDelegate: pass response header through #680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Sources/AsyncHTTPClient/FileDownloadDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import NIOPosix

/// Handles a streaming download to a given file path, allowing headers and progress to be reported.
public final class FileDownloadDelegate: HTTPClientResponseDelegate {
/// The response type for this delegate: the total count of bytes as reported by the response
/// "Content-Length" header (if available) and the count of bytes downloaded.
/// The response type for this delegate: the response header, the total count of bytes as reported,
/// by the response "Content-Length" header (if available) and the count of bytes downloaded.
public struct Progress: Sendable {
public var responseHead: HTTPResponseHead?
public var totalBytes: Int?
public var receivedBytes: Int
}
Expand Down Expand Up @@ -97,6 +98,7 @@ public final class FileDownloadDelegate: HTTPClientResponseDelegate {
task: HTTPClient.Task<Response>,
_ head: HTTPResponseHead
) -> EventLoopFuture<Void> {
self.progress.responseHead = head
self.reportHead?(head)

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