From 6dd1dde9807d2c7b765ff5a4501e5c3e0794ba10 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Tue, 29 Aug 2023 10:00:33 +0200 Subject: [PATCH] Adopt the new shared HTTP client --- Package.swift | 4 +-- .../AsyncHTTPClientTransport.swift | 26 +++++++------------ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/Package.swift b/Package.swift index 04afd62..f093651 100644 --- a/Package.swift +++ b/Package.swift @@ -38,8 +38,8 @@ let package = Package( ), ], dependencies: [ - .package(url: "https://github.com/apple/swift-nio", from: "2.51.0"), - .package(url: "https://github.com/swift-server/async-http-client.git", from: "1.17.0"), + .package(url: "https://github.com/apple/swift-nio", from: "2.58.0"), + .package(url: "https://github.com/swift-server/async-http-client.git", from: "1.19.0"), .package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.1.3")), .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), ], diff --git a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift index f09fdbb..1c5c27a 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -30,23 +30,9 @@ import protocol Foundation.LocalizedError /// /// ### Use the AsyncHTTPClient transport /// -/// Create the underlying HTTP client: +/// Instantiate the transport: /// -/// let httpClient = HTTPClient(eventLoopGroupProvider: .createNew) -/// -/// Either store a reference to the client elsewhere and shut it down during -/// cleanup, or add a defer block if the client is only used in the current -/// scope: -/// -/// defer { -/// try! httpClient.syncShutdown() -/// } -/// -/// Instantiate the transport and provide the HTTP client to it: -/// -/// let transport = AsyncHTTPClientTransport( -/// configuration: .init(client: httpClient) -/// ) +/// let transport = AsyncHTTPClientTransport() /// /// Create the base URL of the server to call using your client. If the server /// URL was defined in the OpenAPI document, you find a generated method for it @@ -68,6 +54,12 @@ import protocol Foundation.LocalizedError /// /// let response = try await client.checkHealth(.init()) /// // ... +/// +/// ### Provide a custom Client +/// +/// The ``AsyncHTTPClientTransport/Configuration-swift.struct`` type allows you +/// to provide a custom `HTTPClient` and tweak behaviors such as the default +/// timeout. public struct AsyncHTTPClientTransport: ClientTransport { /// A set of configuration values for the AsyncHTTPClient transport. @@ -83,7 +75,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { /// - Parameters: /// - client: The underlying client used to perform HTTP operations. /// - timeout: The request timeout, defaults to 1 minute. - public init(client: HTTPClient, timeout: TimeAmount = .minutes(1)) { + public init(client: HTTPClient = .init(), timeout: TimeAmount = .minutes(1)) { self.client = client self.timeout = timeout }