diff --git a/Sources/AsyncHTTPClient/HTTPClient.swift b/Sources/AsyncHTTPClient/HTTPClient.swift index 6c5a9af20..c52263318 100644 --- a/Sources/AsyncHTTPClient/HTTPClient.swift +++ b/Sources/AsyncHTTPClient/HTTPClient.swift @@ -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. @@ -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 } } diff --git a/Tests/AsyncHTTPClientTests/HTTPClientNIOTSTests.swift b/Tests/AsyncHTTPClientTests/HTTPClientNIOTSTests.swift index be03f6a6a..3bbac632b 100644 --- a/Tests/AsyncHTTPClientTests/HTTPClientNIOTSTests.swift +++ b/Tests/AsyncHTTPClientTests/HTTPClientNIOTSTests.swift @@ -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 { @@ -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) @@ -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