@@ -49,36 +49,61 @@ public final class HTTPClientCopyingDelegate: HTTPClientResponseDelegate {
4949}
5050
5151extension ClientBootstrap {
52- fileprivate static func makeBootstrap( on eventLoop: EventLoop , host: String , requiresTLS: Bool , configuration: HTTPClient . Configuration ) throws -> NIOClientTCPBootstrap {
52+ fileprivate static func makeBootstrap(
53+ on eventLoop: EventLoop ,
54+ host: String ,
55+ requiresTLS: Bool ,
56+ configuration: HTTPClient . Configuration
57+ ) throws -> NIOClientTCPBootstrap {
5358 let tlsConfiguration = configuration. tlsConfiguration ?? TLSConfiguration . forClient ( )
5459 let sslContext = try NIOSSLContext ( configuration: tlsConfiguration)
55- let tlsProvider = try NIOSSLClientTLSProvider < ClientBootstrap > ( context: sslContext, serverHostname: ( !requiresTLS || host. isIPAddress) ? nil : host)
60+ let hostname = ( !requiresTLS || host. isIPAddress) ? nil : host
61+ let tlsProvider = try NIOSSLClientTLSProvider < ClientBootstrap > ( context: sslContext, serverHostname: hostname)
5662 return NIOClientTCPBootstrap ( ClientBootstrap ( group: eventLoop) , tls: tlsProvider)
5763 }
5864}
5965
6066extension NIOClientTCPBootstrap {
6167 /// create a TCP Bootstrap based off what type of `EventLoop` has been passed to the function.
62- fileprivate static func makeBootstrap( on eventLoop: EventLoop , host: String , requiresTLS: Bool , configuration: HTTPClient . Configuration ) throws -> NIOClientTCPBootstrap {
68+ fileprivate static func makeBootstrap(
69+ on eventLoop: EventLoop ,
70+ host: String ,
71+ requiresTLS: Bool ,
72+ configuration: HTTPClient . Configuration
73+ ) throws -> NIOClientTCPBootstrap {
6374 let bootstrap : NIOClientTCPBootstrap
6475 #if canImport(Network)
6576 if #available( OSX 10 . 14 , iOS 12 . 0 , tvOS 12 . 0 , watchOS 6 . 0 , * ) , eventLoop is NIOTSEventLoop {
66- let tlsProvider = NIOTSClientTLSProvider ( tlsOptions: . init( ) )
67- bootstrap = NIOClientTCPBootstrap ( NIOTSConnectionBootstrap ( group: eventLoop) , tls: tlsProvider)
77+ if configuration. proxy != nil , requiresTLS {
78+ let tlsConfiguration = configuration. tlsConfiguration ?? TLSConfiguration . forClient ( )
79+ let sslContext = try NIOSSLContext ( configuration: tlsConfiguration)
80+ let hostname = ( !requiresTLS || host. isIPAddress) ? nil : host
81+ bootstrap = try NIOClientTCPBootstrap ( NIOTSConnectionBootstrap ( group: eventLoop) , tls: NIOSSLClientTLSProvider ( context: sslContext, serverHostname: hostname) )
82+ } else {
83+ let tlsProvider = NIOTSClientTLSProvider ( tlsOptions: . init( ) )
84+ bootstrap = NIOClientTCPBootstrap ( NIOTSConnectionBootstrap ( group: eventLoop) , tls: tlsProvider)
85+ }
6886 } else {
6987 bootstrap = try ClientBootstrap . makeBootstrap ( on: eventLoop, host: host, requiresTLS: requiresTLS, configuration: configuration)
7088 }
7189 #else
7290 bootstrap = try ClientBootstrap . makeBootstrap ( on: eventLoop, host: host, requiresTLS: requiresTLS, configuration: configuration)
7391 #endif
7492
75- if requiresTLS {
93+ // don't enable TLS if we have a proxy, this will be enabled later on
94+ if requiresTLS, configuration. proxy == nil {
7695 return bootstrap. enableTLS ( )
7796 }
7897 return bootstrap
7998 }
8099
81- static func makeHTTPClientBootstrapBase( on eventLoop: EventLoop , host: String , port: Int , requiresTLS: Bool , configuration: HTTPClient . Configuration ) throws -> NIOClientTCPBootstrap {
100+ static func makeHTTPClientBootstrapBase(
101+ on eventLoop: EventLoop ,
102+ host: String ,
103+ port: Int ,
104+ requiresTLS: Bool ,
105+ configuration: HTTPClient . Configuration
106+ ) throws -> NIOClientTCPBootstrap {
82107 return try makeBootstrap ( on: eventLoop, host: host, requiresTLS: requiresTLS, configuration: configuration)
83108 . channelOption ( ChannelOptions . socket ( SocketOptionLevel ( IPPROTO_TCP) , TCP_NODELAY) , value: 1 )
84109 . channelInitializer { channel in
0 commit comments