Skip to content
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

Make willSend async #11

Merged
merged 1 commit into from Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/APIClient/APIClient.swift
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
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