diff --git a/Sources/XKit/GrandSlam/Anisette/ADIDataProvider.swift b/Sources/XKit/GrandSlam/Anisette/ADIDataProvider.swift index 16ee784f..07a023b7 100644 --- a/Sources/XKit/GrandSlam/Anisette/ADIDataProvider.swift +++ b/Sources/XKit/GrandSlam/Anisette/ADIDataProvider.swift @@ -178,7 +178,7 @@ public struct ADIDataProvider: AnisetteDataProvider { request.headerFields[.init(key)!] = value } - let (_, response) = try await self.httpClient.makeRequest(request, body: body) + let (_, response) = try await self.httpClient.makeRequest(request, body: body, ephemeral: true) return try GrandSlamOperationDecoder.decode(data: response) } diff --git a/Sources/XKit/GrandSlam/GrandSlamClient.swift b/Sources/XKit/GrandSlam/GrandSlamClient.swift index 640c9fca..d3dd5fd5 100644 --- a/Sources/XKit/GrandSlam/GrandSlamClient.swift +++ b/Sources/XKit/GrandSlam/GrandSlamClient.swift @@ -42,9 +42,7 @@ struct GrandSlamClient: Sendable { // GrandSlam doesn't seem to like reused (keep-alive) connections so create a // new one for each request. cf https://github.com/rileytestut/AltSign/pull/52 - let resp = try await httpClient.withEphemeralClient { - try await $0.makeRequest(httpRequest, body: body) - } + let resp = try await httpClient.makeRequest(httpRequest, body: body, ephemeral: true) return try R.Decoder.decode(data: resp.body) } diff --git a/Sources/XKit/GrandSlam/Lookup/GrandSlamLookupManager.swift b/Sources/XKit/GrandSlam/Lookup/GrandSlamLookupManager.swift index 756afa1f..63540732 100644 --- a/Sources/XKit/GrandSlam/Lookup/GrandSlamLookupManager.swift +++ b/Sources/XKit/GrandSlam/Lookup/GrandSlamLookupManager.swift @@ -42,7 +42,7 @@ actor GrandSlamLookupManager { request.headerFields[.init(key)!] = value } - let (_, body) = try await httpClient.makeRequest(request) + let (_, body) = try await httpClient.makeRequest(request, ephemeral: true) return try self.decoder.decode(Response.self, from: body).urls } diff --git a/Sources/XKit/HTTPClientProtocol/HTTPClientProtocol.swift b/Sources/XKit/HTTPClientProtocol/HTTPClientProtocol.swift index 503a0036..22923d26 100644 --- a/Sources/XKit/HTTPClientProtocol/HTTPClientProtocol.swift +++ b/Sources/XKit/HTTPClientProtocol/HTTPClientProtocol.swift @@ -46,8 +46,21 @@ extension HTTPClientProtocol { _ request: HTTPRequest, body: Data? = nil, requireHTTPSuccess: Bool = true, + ephemeral: Bool = false, onProgress: @isolated(any) (Double?) -> Void = { _ in } ) async throws -> (response: HTTPResponse, body: Data) { + if ephemeral { + return try await self.withEphemeralClient { client in + try await client.makeRequest( + request, + body: body, + requireHTTPSuccess: requireHTTPSuccess, + ephemeral: false, + onProgress: onProgress + ) + } + } + await onProgress(0) let (response, responseBody) = try await send(request, body: body.map { HTTPBody($0) }) guard !requireHTTPSuccess || ![.clientError, .serverError].contains(response.status.kind) else {