Skip to content

armgit / xtool

Public Imported from GitHub
0

Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.

gsa: make more reqs ephemeral (#417)

Kabir Oberai804cf3e1ddaa
diff --git a/Sources/XKit/GrandSlam/Anisette/ADIDataProvider.swift b/Sources/XKit/GrandSlam/Anisette/ADIDataProvider.swift
index 16ee784..07a023b 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<Response>.decode(data: response)
}
diff --git a/Sources/XKit/GrandSlam/GrandSlamClient.swift b/Sources/XKit/GrandSlam/GrandSlamClient.swift
index 640c9fc..d3dd5fd 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 756afa1..6354073 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 503a003..22923d2 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 {