From 08cf95f9b53e9adf28447550f2c7830de4a10f7a Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Wed, 12 Apr 2023 17:14:05 +0100 Subject: [PATCH 1/3] FileDownloadDelegate: pass response header through Currently `FileDownloadDelegate` doesn't pass the response header through in its `Response` associated type, which is satisfied by the `Progress` inner type declaration. This makes it hard to use in the Swift Concurrency context, since it's no trivial to pass response header around from `reportHead` closure. Let's fix that by adding a new field that passes the response header in the delegate's response. This change is additive and is not source-breaking. --- Sources/AsyncHTTPClient/FileDownloadDelegate.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/AsyncHTTPClient/FileDownloadDelegate.swift b/Sources/AsyncHTTPClient/FileDownloadDelegate.swift index c328c7211..afcdb387d 100644 --- a/Sources/AsyncHTTPClient/FileDownloadDelegate.swift +++ b/Sources/AsyncHTTPClient/FileDownloadDelegate.swift @@ -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 reponseHead: HTTPResponseHead? public var totalBytes: Int? public var receivedBytes: Int } @@ -97,6 +98,7 @@ public final class FileDownloadDelegate: HTTPClientResponseDelegate { task: HTTPClient.Task, _ head: HTTPResponseHead ) -> EventLoopFuture { + self.progress.responseHead = head self.reportHead?(head) if let totalBytesString = head.headers.first(name: "Content-Length"), From d42c7021065e6ee82e64ab5db6d9b3f02abb33cd Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Wed, 12 Apr 2023 17:15:14 +0100 Subject: [PATCH 2/3] FileDownloadDelegate: fix field name typo --- Sources/AsyncHTTPClient/FileDownloadDelegate.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AsyncHTTPClient/FileDownloadDelegate.swift b/Sources/AsyncHTTPClient/FileDownloadDelegate.swift index afcdb387d..f8776c7c2 100644 --- a/Sources/AsyncHTTPClient/FileDownloadDelegate.swift +++ b/Sources/AsyncHTTPClient/FileDownloadDelegate.swift @@ -21,7 +21,7 @@ public final class FileDownloadDelegate: HTTPClientResponseDelegate { /// 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 reponseHead: HTTPResponseHead? + public var responseHead: HTTPResponseHead? public var totalBytes: Int? public var receivedBytes: Int } From 087416238484ef339e6f1c1fa4619500e498b9c9 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Wed, 12 Apr 2023 17:24:08 +0100 Subject: [PATCH 3/3] FileDownloadDelegate: remove trailing whitespace --- Sources/AsyncHTTPClient/FileDownloadDelegate.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AsyncHTTPClient/FileDownloadDelegate.swift b/Sources/AsyncHTTPClient/FileDownloadDelegate.swift index f8776c7c2..588fccb29 100644 --- a/Sources/AsyncHTTPClient/FileDownloadDelegate.swift +++ b/Sources/AsyncHTTPClient/FileDownloadDelegate.swift @@ -18,7 +18,7 @@ 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 response header, the total count of bytes as reported + /// 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?