From 804cf3e1ddaaa84d11f20b6dcbe86927be9e036d Mon Sep 17 00:00:00 2001 From: Kabir Oberai Date: Fri, 30 Oct 2026 21:54:54 -0400 Subject: [PATCH] gsa: make more reqs ephemeral (#417) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What does this PR do? I'm not sure if this is needed but, for good measure, updates remaining GSA requests to use an ephemeral client (followup from #247) ## How was it tested? - [x] Tested flows involving all of these requests ## AI tool usage How much of the code in this PR was AI-assisted? (check one) - [x] **0** - No AI was used to write code - [ ] **1** - I was assisted by AI in writing code. I reviewed the finished result. - [ ] **2** - I set the AI going and left it to it; nobody has read the result - no review, or AI review only ## Summary by CodeRabbit * **Improvements** * Selected account and lookup requests now use temporary HTTP connections. Existing request details, response handling, and progress reporting remain supported, while other requests continue through the standard connection flow. This change applies across the app’s related account and lookup operations; no new user-facing controls or workflows are introduced. --- .../XKit/GrandSlam/Anisette/ADIDataProvider.swift | 2 +- Sources/XKit/GrandSlam/GrandSlamClient.swift | 4 +--- .../GrandSlam/Lookup/GrandSlamLookupManager.swift | 2 +- .../HTTPClientProtocol/HTTPClientProtocol.swift | 13 +++++++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) 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 {