Skip to content

Commit 6e4f181

Browse files
committed
Merge branch 'main' of https://github.com/kean/APIClient
2 parents 0f46e64 + 381cefa commit 6e4f181

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# APIClient 0.x
22

3+
## Upcoming Release
4+
5+
- Make `willSend` async - [#11](https://github.com/kean/APIClient/pull/11), thanks to [Lars-Jørgen Kristiansen](https://github.com/LarsJK)
6+
37
## APIClient 0.0.6
48

59
*Dec 13, 2021*

Sources/Get/APIClient.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import Foundation
66

77
public protocol APIClientDelegate {
8-
func client(_ client: APIClient, willSendRequest request: inout URLRequest)
8+
func client(_ client: APIClient, willSendRequest request: inout URLRequest) async
99
func shouldClientRetry(_ client: APIClient, withError error: Error) async -> Bool
1010
func client(_ client: APIClient, didReceiveInvalidResponse response: HTTPURLResponse, data: Data) -> Error
1111
}
@@ -104,7 +104,7 @@ public actor APIClient {
104104

105105
private func actuallySend(_ request: URLRequest) async throws -> Response<Data> {
106106
var request = request
107-
delegate.client(self, willSendRequest: &request)
107+
await delegate.client(self, willSendRequest: &request)
108108
let (data, response) = try await session.data(for: request, delegate: nil)
109109
try validate(response: response, data: data)
110110
let httpResponse = (response as? HTTPURLResponse) ?? HTTPURLResponse() // The right side should never be executed

Tests/GetTests/APIClientTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private func json(named name: String) -> Data {
219219
private final class MockAuthorizatingDelegate: APIClientDelegate {
220220
var token = "expired-token"
221221

222-
func client(_ client: APIClient, willSendRequest request: inout URLRequest) {
222+
func client(_ client: APIClient, willSendRequest request: inout URLRequest) async {
223223
request.allHTTPHeaderFields = ["Authorization": "Bearer: \(token)"]
224224
}
225225

0 commit comments

Comments
 (0)