Skip to content

Commit

Permalink
Merge pull request #11 from LarsJK/async-will-send
Browse files Browse the repository at this point in the history
Make willSend async
  • Loading branch information
kean authored Dec 16, 2021
2 parents 71aeac4 + 3cd7bff commit 731689f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Sources/APIClient/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import Foundation

public protocol APIClientDelegate {
func client(_ client: APIClient, willSendRequest request: inout URLRequest)
func client(_ client: APIClient, willSendRequest request: inout URLRequest) async
func shouldClientRetry(_ client: APIClient, withError error: Error) async -> Bool
func client(_ client: APIClient, didReceiveInvalidResponse response: HTTPURLResponse, data: Data) -> Error
}
Expand Down Expand Up @@ -104,7 +104,7 @@ public actor APIClient {

private func actuallySend(_ request: URLRequest) async throws -> Response<Data> {
var request = request
delegate.client(self, willSendRequest: &request)
await delegate.client(self, willSendRequest: &request)
let (data, response) = try await session.data(for: request, delegate: nil)
try validate(response: response, data: data)
let httpResponse = (response as? HTTPURLResponse) ?? HTTPURLResponse() // The right side should never be executed
Expand Down
2 changes: 1 addition & 1 deletion Tests/APIClientTests/APIClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private func json(named name: String) -> Data {
private final class MockAuthorizatingDelegate: APIClientDelegate {
var token = "expired-token"

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

Expand Down

0 comments on commit 731689f

Please sign in to comment.