Skip to content

Use HTTPClient.shared as default #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -19,7 +19,9 @@ import PackageDescription
let swiftSettings: [SwiftSetting] = [
// https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md
// Require `any` for existential types.
.enableUpcomingFeature("ExistentialAny")
.enableUpcomingFeature("ExistentialAny"),
// Enable Strict Concurrency Checks for Swift 6 compatibility.
.enableExperimentalFeature("StrictConcurrency=complete"),
]

let package = Package(
@@ -35,7 +37,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"),
16 changes: 5 additions & 11 deletions Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ import NIOCore
import NIOHTTP1
import NIOFoundationCompat
import HTTPTypes
#if canImport(Darwin)
#if canImport(Darwin) || swift(>=6.0)
import Foundation
#else
@preconcurrency import struct Foundation.URL
@@ -62,24 +62,18 @@ 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.
/// Provide nil to use `HTTPClient.shared`.
/// - timeout: The request timeout, defaults to 1 minute.
public init(client: HTTPClient? = nil, timeout: TimeAmount = .minutes(1)) {
self.client = client ?? Self.sharedClient
// FIXME: `client: HTTPClient? = nil` should be changed to `client: HTTPClient = .shared`
// in a future major version, now that `AsyncHTTPClient` provides a shared `HTTPClient`.
self.client = client ?? HTTPClient.shared
self.timeout = timeout
}
}