From 961833ba7033d2416507451cd5ba98868ece8ce8 Mon Sep 17 00:00:00 2001 From: David Nadoba Date: Wed, 10 Nov 2021 17:17:00 +0100 Subject: [PATCH 1/4] make HTTPVersion public and set to .automatic by default --- Sources/AsyncHTTPClient/HTTPClient.swift | 19 +++++++------------ .../HTTP2ClientTests.swift | 3 +-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Sources/AsyncHTTPClient/HTTPClient.swift b/Sources/AsyncHTTPClient/HTTPClient.swift index b5a4e7b2d..a00cb51f8 100644 --- a/Sources/AsyncHTTPClient/HTTPClient.swift +++ b/Sources/AsyncHTTPClient/HTTPClient.swift @@ -607,10 +607,8 @@ public class HTTPClient { set {} } - // TODO: make public - // TODO: set to automatic by default - /// HTTP/2 is by default disabled - internal var httpVersion: HTTPVersion + /// is set to `.automatic` by default which will use HTTP/2 if run over https and the server supports it, otherwise HTTP/1 + public var httpVersion: HTTPVersion public init( tlsConfiguration: TLSConfiguration? = nil, @@ -628,13 +626,11 @@ public class HTTPClient { proxy: proxy, ignoreUncleanSSLShutdown: ignoreUncleanSSLShutdown, decompression: decompression, - // TODO: set to automatic by default - httpVersion: .http1Only + httpVersion: .automatic ) } - // TODO: make public - internal init( + public init( tlsConfiguration: TLSConfiguration? = nil, redirectConfiguration: RedirectConfiguration? = nil, timeout: Timeout = Timeout(), @@ -865,18 +861,17 @@ extension HTTPClient.Configuration { } } - // TODO: make this struct and its static properties public - internal struct HTTPVersion { + public struct HTTPVersion { internal enum Configuration { case http1Only case automatic } /// we only use HTTP/1, even if the server would supports HTTP/2 - internal static let http1Only: Self = .init(configuration: .http1Only) + public static let http1Only: Self = .init(configuration: .http1Only) /// HTTP/2 is used if we connect to a server with HTTPS and the server supports HTTP/2, otherwise we use HTTP/1 - internal static let automatic: Self = .init(configuration: .automatic) + public static let automatic: Self = .init(configuration: .automatic) internal var configuration: Configuration } diff --git a/Tests/AsyncHTTPClientTests/HTTP2ClientTests.swift b/Tests/AsyncHTTPClientTests/HTTP2ClientTests.swift index 34076f75c..f98258502 100644 --- a/Tests/AsyncHTTPClientTests/HTTP2ClientTests.swift +++ b/Tests/AsyncHTTPClientTests/HTTP2ClientTests.swift @@ -12,8 +12,7 @@ // //===----------------------------------------------------------------------===// -// TODO: remove @testable once we officially support HTTP/2 -@testable import AsyncHTTPClient // Tests that really need @testable go into HTTP2ClientInternalTests.swift +/* NOT @testable */ import AsyncHTTPClient // Tests that really need @testable go into HTTP2ClientInternalTests.swift #if canImport(Network) import Network #endif From 59939033db76e1bdeec67d37bd7c66a921a14f44 Mon Sep 17 00:00:00 2001 From: David Nadoba Date: Thu, 11 Nov 2021 11:55:45 +0100 Subject: [PATCH 2/4] make `Configuration.init` with `HTTPVersion` internal --- Sources/AsyncHTTPClient/HTTPClient.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AsyncHTTPClient/HTTPClient.swift b/Sources/AsyncHTTPClient/HTTPClient.swift index a00cb51f8..1f9daeb70 100644 --- a/Sources/AsyncHTTPClient/HTTPClient.swift +++ b/Sources/AsyncHTTPClient/HTTPClient.swift @@ -630,7 +630,7 @@ public class HTTPClient { ) } - public init( + internal init( tlsConfiguration: TLSConfiguration? = nil, redirectConfiguration: RedirectConfiguration? = nil, timeout: Timeout = Timeout(), From 7a1d6255b2e5b69a463dac8f29b4a2e3dfe26876 Mon Sep 17 00:00:00 2001 From: David Nadoba Date: Thu, 11 Nov 2021 11:30:48 +0100 Subject: [PATCH 3/4] remove init with HTTPVersion --- Sources/AsyncHTTPClient/HTTPClient.swift | 23 +------------------ .../HTTP2ConnectionTests.swift | 8 +++++-- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/Sources/AsyncHTTPClient/HTTPClient.swift b/Sources/AsyncHTTPClient/HTTPClient.swift index 1f9daeb70..a1f699546 100644 --- a/Sources/AsyncHTTPClient/HTTPClient.swift +++ b/Sources/AsyncHTTPClient/HTTPClient.swift @@ -618,27 +618,6 @@ public class HTTPClient { proxy: Proxy? = nil, ignoreUncleanSSLShutdown: Bool = false, decompression: Decompression = .disabled - ) { - self.init( - tlsConfiguration: tlsConfiguration, - redirectConfiguration: redirectConfiguration, - timeout: timeout, connectionPool: connectionPool, - proxy: proxy, - ignoreUncleanSSLShutdown: ignoreUncleanSSLShutdown, - decompression: decompression, - httpVersion: .automatic - ) - } - - internal init( - tlsConfiguration: TLSConfiguration? = nil, - redirectConfiguration: RedirectConfiguration? = nil, - timeout: Timeout = Timeout(), - connectionPool: ConnectionPool = ConnectionPool(), - proxy: Proxy? = nil, - ignoreUncleanSSLShutdown: Bool = false, - decompression: Decompression = .disabled, - httpVersion: HTTPVersion ) { self.tlsConfiguration = tlsConfiguration self.redirectConfiguration = redirectConfiguration ?? RedirectConfiguration() @@ -646,7 +625,7 @@ public class HTTPClient { self.connectionPool = connectionPool self.proxy = proxy self.decompression = decompression - self.httpVersion = httpVersion + self.httpVersion = .automatic } public init(tlsConfiguration: TLSConfiguration? = nil, diff --git a/Tests/AsyncHTTPClientTests/HTTP2ConnectionTests.swift b/Tests/AsyncHTTPClientTests/HTTP2ConnectionTests.swift index 4bbe013d0..23c14d159 100644 --- a/Tests/AsyncHTTPClientTests/HTTP2ConnectionTests.swift +++ b/Tests/AsyncHTTPClientTests/HTTP2ConnectionTests.swift @@ -250,10 +250,12 @@ class TestConnectionCreator { var tlsConfiguration = TLSConfiguration.makeClientConfiguration() tlsConfiguration.certificateVerification = .none + var config = HTTPClient.Configuration() + config.httpVersion = .automatic let factory = HTTPConnectionPool.ConnectionFactory( key: .init(request), tlsConfiguration: tlsConfiguration, - clientConfiguration: .init(httpVersion: .automatic), + clientConfiguration: config, sslContextCache: .init() ) @@ -291,10 +293,12 @@ class TestConnectionCreator { var tlsConfiguration = TLSConfiguration.makeClientConfiguration() tlsConfiguration.certificateVerification = .none + var config = HTTPClient.Configuration() + config.httpVersion = .automatic let factory = HTTPConnectionPool.ConnectionFactory( key: .init(request), tlsConfiguration: tlsConfiguration, - clientConfiguration: .init(httpVersion: .automatic), + clientConfiguration: config, sslContextCache: .init() ) From 5bf0bf63b2c32927df35307bfdaec01250458ac4 Mon Sep 17 00:00:00 2001 From: David Nadoba Date: Thu, 11 Nov 2021 12:03:32 +0100 Subject: [PATCH 4/4] fix merge conflicts --- .../HTTP2ClientTests.swift | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/Tests/AsyncHTTPClientTests/HTTP2ClientTests.swift b/Tests/AsyncHTTPClientTests/HTTP2ClientTests.swift index f98258502..934205f31 100644 --- a/Tests/AsyncHTTPClientTests/HTTP2ClientTests.swift +++ b/Tests/AsyncHTTPClientTests/HTTP2ClientTests.swift @@ -27,14 +27,13 @@ class HTTP2ClientTests: XCTestCase { func makeDefaultHTTPClient( eventLoopGroupProvider: HTTPClient.EventLoopGroupProvider = .createNew ) -> HTTPClient { - var tlsConfig = TLSConfiguration.makeClientConfiguration() - tlsConfig.certificateVerification = .none + var config = HTTPClient.Configuration() + config.tlsConfiguration = .clientDefault + config.tlsConfiguration?.certificateVerification = .none + config.httpVersion = .automatic return HTTPClient( eventLoopGroupProvider: eventLoopGroupProvider, - configuration: HTTPClient.Configuration( - tlsConfiguration: tlsConfig, - httpVersion: .automatic - ), + configuration: config, backgroundActivityLogger: Logger(label: "HTTPClient", factory: StreamLogHandler.standardOutput(label:)) ) } @@ -137,14 +136,13 @@ class HTTP2ClientTests: XCTestCase { let localHTTPBin = HTTPBin(.http2(compress: false)) let elg = MultiThreadedEventLoopGroup(numberOfThreads: numberOfWorkers) - var tlsConfig = TLSConfiguration.makeClientConfiguration() - tlsConfig.certificateVerification = .none + var config = HTTPClient.Configuration() + config.tlsConfiguration = .clientDefault + config.tlsConfiguration?.certificateVerification = .none + config.httpVersion = .automatic let localClient = HTTPClient( eventLoopGroupProvider: .shared(elg), - configuration: HTTPClient.Configuration( - tlsConfiguration: tlsConfig, - httpVersion: .automatic - ), + configuration: config, backgroundActivityLogger: Logger(label: "HTTPClient", factory: StreamLogHandler.standardOutput(label:)) ) defer { @@ -302,15 +300,14 @@ class HTTP2ClientTests: XCTestCase { let el1 = clientGroup.next() let el2 = clientGroup.next() defer { XCTAssertNoThrow(try clientGroup.syncShutdownGracefully()) } - var tlsConfig = TLSConfiguration.makeClientConfiguration() - tlsConfig.certificateVerification = .none + var config = HTTPClient.Configuration() + config.tlsConfiguration = .clientDefault + config.tlsConfiguration?.certificateVerification = .none + config.httpVersion = .automatic + config.timeout.connect = .milliseconds(1000) let client = HTTPClient( eventLoopGroupProvider: .shared(clientGroup), - configuration: HTTPClient.Configuration( - tlsConfiguration: tlsConfig, - timeout: .init(connect: .milliseconds(1000)), - httpVersion: .automatic - ), + configuration: config, backgroundActivityLogger: Logger(label: "HTTPClient", factory: StreamLogHandler.standardOutput(label:)) ) defer { XCTAssertNoThrow(try client.syncShutdown()) }