Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7b96b1d

Browse files
Adopt AHC's .shared singleton as the default Client (#39)
### Motivation As a convenience when you don't need to create a custom AHC Client instance, we provide a singleton client as the default. AHC added their own `Client.shared` singleton, so let's adopt that and remove the transport's internal singleton, which was used for the same purpose. ### Modifications - Replaced the tranport's internal singleton with the AHC-provided one. - Use Int64 directly and skip conversions now that AHC also uses Int64 for the body byte size. ### Result - No internal singleton is created now, possibly avoiding having two AHC singletons in a given process. - Fixed a warning around Int/Int64 conversion. ### Test Plan Unit tests still pass.
1 parent abfe558 commit 7b96b1d

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

‎Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let package = Package(
3535
],
3636
dependencies: [
3737
.package(url: "https://github.com/apple/swift-nio", from: "2.58.0"),
38-
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.19.0"),
38+
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.23.0"),
3939
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
4040
.package(url: "https://github.com/apple/swift-http-types", from: "1.0.0"),
4141
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),

‎Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,27 @@ public struct AsyncHTTPClientTransport: ClientTransport {
6262
/// The HTTP client used for performing HTTP calls.
6363
public var client: HTTPClient
6464

65-
/// The default shared HTTP client.
66-
///
67-
/// This is a workaround for the lack of a shared client
68-
/// in AsyncHTTPClient. Do not use this value directly, outside of
69-
/// the `Configuration.init(client:timeout:)` initializer, as it will
70-
/// likely be removed in the future.
71-
private static let sharedClient: HTTPClient = .init()
72-
7365
/// The default request timeout.
7466
public var timeout: TimeAmount
7567

7668
/// Creates a new configuration with the specified client and timeout.
7769
/// - Parameters:
7870
/// - client: The underlying client used to perform HTTP operations.
79-
/// Provide nil to use the shared internal client.
8071
/// - timeout: The request timeout, defaults to 1 minute.
81-
public init(client: HTTPClient? = nil, timeout: TimeAmount = .minutes(1)) {
82-
self.client = client??Self.sharedClient
72+
public init(client: HTTPClient = .shared, timeout: TimeAmount = .minutes(1)) {
73+
self.client = client
8374
self.timeout = timeout
8475
}
76+
77+
/// Creates a new configuration with the specified client and timeout.
78+
/// - Parameters:
79+
/// - client: The underlying client used to perform HTTP operations.
80+
/// Provide nil to use the shared client.
81+
/// - timeout: The request timeout, defaults to 1 minute.
82+
@available(*, deprecated, message: "Use the initializer with a non-optional client parameter.")
83+
@_disfavoredOverload public init(client: HTTPClient? = nil, timeout: TimeAmount = .minutes(1)) {
84+
self.init(client: client ?? .shared, timeout: timeout)
85+
}
8586
}
8687

8788
/// A request to be sent by the transport.
@@ -174,8 +175,7 @@ public struct AsyncHTTPClientTransport: ClientTransport {
174175
let length: HTTPClientRequest.Body.Length
175176
switch body.length {
176177
case .unknown: length = .unknown
177-
case .known(let count):
178-
if let intValue = Int(exactly: count) { length = .known(intValue) } else { length = .unknown }
178+
case .known(let count): length = .known(count)
179179
}
180180
clientRequest.body = .stream(body.map { .init(bytes: 0ドル) }, length: length)
181181
}

‎docker/docker-compose.2204.main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
test:
1111
image: *image
1212
environment:
13-
- WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors
13+
#- WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors
1414
- IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error
1515
- STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete
1616

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /