From c0d1cff35abc8523eb800d65d7eda67997279661 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Mon, 23 Sep 2024 09:16:59 +0200 Subject: [PATCH 1/3] Adopt AHC's .shared singleton as the default Client --- Package.swift | 2 +- .../AsyncHTTPClientTransport.swift | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Package.swift b/Package.swift index c1d69ba..0757d44 100644 --- a/Package.swift +++ b/Package.swift @@ -35,7 +35,7 @@ let package = Package( ], dependencies: [ .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/swift-server/async-http-client.git", from: "1.21.0"), .package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"), .package(url: "https://github.com/apple/swift-http-types", from: "1.0.0"), .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 d16220e..2b71120 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -62,26 +62,27 @@ public struct AsyncHTTPClientTransport: ClientTransport { /// The HTTP client used for performing HTTP calls. public var client: HTTPClient - /// The default shared HTTP client. - /// - /// This is a workaround for the lack of a shared client - /// in AsyncHTTPClient. Do not use this value directly, outside of - /// the `Configuration.init(client:timeout:)` initializer, as it will - /// likely be removed in the future. - private static let sharedClient: HTTPClient = .init() - /// The default request timeout. public var timeout: TimeAmount /// Creates a new configuration with the specified client and timeout. /// - Parameters: /// - client: The underlying client used to perform HTTP operations. - /// Provide nil to use the shared internal client. /// - timeout: The request timeout, defaults to 1 minute. - public init(client: HTTPClient? = nil, timeout: TimeAmount = .minutes(1)) { - self.client = client ?? Self.sharedClient + public init(client: HTTPClient = .shared, timeout: TimeAmount = .minutes(1)) { + self.client = client self.timeout = timeout } + + /// Creates a new configuration with the specified client and timeout. + /// - Parameters: + /// - client: The underlying client used to perform HTTP operations. + /// Provide nil to use the shared client. + /// - timeout: The request timeout, defaults to 1 minute. + @available(*, deprecated, renamed: "init(client:timeout:)") @_disfavoredOverload public init( + client: HTTPClient? = nil, + timeout: TimeAmount = .minutes(1) + ) { self.init(client: client ?? .shared, timeout: timeout) } } /// A request to be sent by the transport. @@ -174,8 +175,7 @@ public struct AsyncHTTPClientTransport: ClientTransport { let length: HTTPClientRequest.Body.Length switch body.length { case .unknown: length = .unknown - case .known(let count): - if let intValue = Int(exactly: count) { length = .known(intValue) } else { length = .unknown } + case .known(let count): length = .known(count) } clientRequest.body = .stream(body.map { .init(bytes: $0) }, length: length) } From d2fde5600cff4237b9e19ca88f1429f68932edea Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Mon, 23 Sep 2024 12:17:02 +0200 Subject: [PATCH 2/3] Disable warnings-as-errors on nightly toolchains, we already do this in other repos --- docker/docker-compose.2204.main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/docker-compose.2204.main.yaml b/docker/docker-compose.2204.main.yaml index b1443e6..323b063 100644 --- a/docker/docker-compose.2204.main.yaml +++ b/docker/docker-compose.2204.main.yaml @@ -10,7 +10,7 @@ services: test: image: *image environment: - - WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors + # - WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error - STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete From bb3a024b9b1888badf187b1e3e37af08543d93e9 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Thu, 3 Oct 2024 17:23:42 +0200 Subject: [PATCH 3/3] PR feedback --- Package.swift | 2 +- .../OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Package.swift b/Package.swift index 0757d44..21c12ed 100644 --- a/Package.swift +++ b/Package.swift @@ -35,7 +35,7 @@ let package = Package( ], dependencies: [ .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.21.0"), + .package(url: "https://github.com/swift-server/async-http-client.git", from: "1.23.0"), .package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"), .package(url: "https://github.com/apple/swift-http-types", from: "1.0.0"), .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 2b71120..39b79d3 100644 --- a/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift +++ b/Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift @@ -79,10 +79,10 @@ public struct AsyncHTTPClientTransport: ClientTransport { /// - client: The underlying client used to perform HTTP operations. /// Provide nil to use the shared client. /// - timeout: The request timeout, defaults to 1 minute. - @available(*, deprecated, renamed: "init(client:timeout:)") @_disfavoredOverload public init( - client: HTTPClient? = nil, - timeout: TimeAmount = .minutes(1) - ) { self.init(client: client ?? .shared, timeout: timeout) } + @available(*, deprecated, message: "Use the initializer with a non-optional client parameter.") + @_disfavoredOverload public init(client: HTTPClient? = nil, timeout: TimeAmount = .minutes(1)) { + self.init(client: client ?? .shared, timeout: timeout) + } } /// A request to be sent by the transport.