Skip to content
13 changes: 7 additions & 6 deletions Sources/AsyncHTTPClient/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1012,11 +1012,11 @@ extension HTTPClient.Configuration {
public struct ConnectionPool: Hashable, Sendable {
/// Specifies amount of time connections are kept idle in the pool. After this time has passed without a new
/// request the connections are closed.
public var idleTimeout: TimeAmount
public var idleTimeout: TimeAmount = .seconds(60)

/// The maximum number of connections that are kept alive in the connection pool per host. If requests with
/// an explicit eventLoopRequirement are sent, this number might be exceeded due to overflow connections.
public var concurrentHTTP1ConnectionsPerHostSoftLimit: Int
public var concurrentHTTP1ConnectionsPerHostSoftLimit: Int = 8

/// If true, ``HTTPClient`` will try to create new connections on connection failure with an exponential backoff.
/// Requests will only fail after the ``HTTPClient/Configuration/Timeout-swift.struct/connect`` timeout exceeded.
Expand All @@ -1025,16 +1025,17 @@ extension HTTPClient.Configuration {
/// - warning: We highly recommend leaving this on.
/// It is very common that connections establishment is flaky at scale.
/// ``HTTPClient`` will automatically mitigate these kind of issues if this flag is turned on.
var retryConnectionEstablishment: Bool
public var retryConnectionEstablishment: Bool = true

public init(idleTimeout: TimeAmount = .seconds(60)) {
self.init(idleTimeout: idleTimeout, concurrentHTTP1ConnectionsPerHostSoftLimit: 8)
public init() {}

public init(idleTimeout: TimeAmount) {
self.idleTimeout = idleTimeout
}

public init(idleTimeout: TimeAmount, concurrentHTTP1ConnectionsPerHostSoftLimit: Int) {
self.idleTimeout = idleTimeout
self.concurrentHTTP1ConnectionsPerHostSoftLimit = concurrentHTTP1ConnectionsPerHostSoftLimit
self.retryConnectionEstablishment = true
}
}

Expand Down
15 changes: 6 additions & 9 deletions Tests/AsyncHTTPClientTests/HTTPClientNIOTSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ class HTTPClientNIOTSTests: XCTestCase {
guard isTestingNIOTS() else { return }

let httpBin = HTTPBin(.http1_1(ssl: true))
var config = HTTPClient.Configuration()
config.networkFrameworkWaitForConnectivity = false
config.connectionPool.retryConnectionEstablishment = false
let config = HTTPClient.Configuration()
.enableFastFailureModeForTesting()
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
configuration: config)
defer {
Expand All @@ -84,9 +83,8 @@ class HTTPClientNIOTSTests: XCTestCase {
guard isTestingNIOTS() else { return }
#if canImport(Network)
let httpBin = HTTPBin(.http1_1(ssl: false))
var config = HTTPClient.Configuration()
config.networkFrameworkWaitForConnectivity = false
config.connectionPool.retryConnectionEstablishment = false
let config = HTTPClient.Configuration()
.enableFastFailureModeForTesting()

let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
configuration: config)
Expand Down Expand Up @@ -140,9 +138,8 @@ class HTTPClientNIOTSTests: XCTestCase {
tlsConfig.minimumTLSVersion = .tlsv11
tlsConfig.maximumTLSVersion = .tlsv1

var clientConfig = HTTPClient.Configuration(tlsConfiguration: tlsConfig)
clientConfig.networkFrameworkWaitForConnectivity = false
clientConfig.connectionPool.retryConnectionEstablishment = false
let clientConfig = HTTPClient.Configuration(tlsConfiguration: tlsConfig)
.enableFastFailureModeForTesting()
let httpClient = HTTPClient(
eventLoopGroupProvider: .shared(self.clientGroup),
configuration: clientConfig
Expand Down