@@ -603,20 +603,51 @@ public class HTTPClient {
603603 /// Ignore TLS unclean shutdown error, defaults to `false`.
604604 public var ignoreUncleanSSLShutdown : Bool
605605
606- public init ( tlsConfiguration: TLSConfiguration ? = nil ,
607- redirectConfiguration: RedirectConfiguration ? = nil ,
608- timeout: Timeout = Timeout ( ) ,
609- connectionPool: ConnectionPool = ConnectionPool ( ) ,
610- proxy: Proxy ? = nil ,
611- ignoreUncleanSSLShutdown: Bool = false ,
612- decompression: Decompression = . disabled) {
606+ // TODO: make public
607+ // TODO: set to automatic by default
608+ /// HTTP/2 is by default disabled
609+ internal var httpVersion : HTTPVersion
610+
611+ public init (
612+ tlsConfiguration: TLSConfiguration ? = nil ,
613+ redirectConfiguration: RedirectConfiguration ? = nil ,
614+ timeout: Timeout = Timeout ( ) ,
615+ connectionPool: ConnectionPool = ConnectionPool ( ) ,
616+ proxy: Proxy ? = nil ,
617+ ignoreUncleanSSLShutdown: Bool = false ,
618+ decompression: Decompression = . disabled
619+ ) {
620+ self . init (
621+ tlsConfiguration: tlsConfiguration,
622+ redirectConfiguration: redirectConfiguration,
623+ timeout: timeout, connectionPool: connectionPool,
624+ proxy: proxy,
625+ ignoreUncleanSSLShutdown: ignoreUncleanSSLShutdown,
626+ decompression: decompression,
627+ // TODO: set to automatic by default
628+ httpVersion: . http1Only
629+ )
630+ }
631+
632+ // TODO: make public
633+ internal init (
634+ tlsConfiguration: TLSConfiguration ? = nil ,
635+ redirectConfiguration: RedirectConfiguration ? = nil ,
636+ timeout: Timeout = Timeout ( ) ,
637+ connectionPool: ConnectionPool = ConnectionPool ( ) ,
638+ proxy: Proxy ? = nil ,
639+ ignoreUncleanSSLShutdown: Bool = false ,
640+ decompression: Decompression = . disabled,
641+ httpVersion: HTTPVersion
642+ ) {
613643 self . tlsConfiguration = tlsConfiguration
614644 self . redirectConfiguration = redirectConfiguration ?? RedirectConfiguration ( )
615645 self . timeout = timeout
616646 self . connectionPool = connectionPool
617647 self . proxy = proxy
618648 self . ignoreUncleanSSLShutdown = ignoreUncleanSSLShutdown
619649 self . decompression = decompression
650+ self . httpVersion = httpVersion
620651 }
621652
622653 public init ( tlsConfiguration: TLSConfiguration ? = nil ,
@@ -830,6 +861,22 @@ extension HTTPClient.Configuration {
830861 self . concurrentHTTP1ConnectionsPerHostSoftLimit = concurrentHTTP1ConnectionsPerHostSoftLimit
831862 }
832863 }
864+
865+ // TODO: make this struct and its static properties public
866+ internal struct HTTPVersion {
867+ internal enum Configuration {
868+ case http1Only
869+ case automatic
870+ }
871+
872+ /// we only use HTTP/1, even if the server would supports HTTP/2
873+ internal static let http1Only : Self = . init( configuration: . http1Only)
874+
875+ /// HTTP/2 is used if we connect to a server with HTTPS and the server supports HTTP/2, otherwise we use HTTP/1
876+ internal static let automatic : Self = . init( configuration: . automatic)
877+
878+ internal var configuration : Configuration
879+ }
833880}
834881
835882/// Possible client errors.
0 commit comments