@@ -49,36 +49,61 @@ public final class HTTPClientCopyingDelegate: HTTPClientResponseDelegate {
49
49
}
50
50
51
51
extension 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 {
53
58
let tlsConfiguration = configuration. tlsConfiguration ?? TLSConfiguration . forClient ( )
54
59
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)
56
62
return NIOClientTCPBootstrap ( ClientBootstrap ( group: eventLoop) , tls: tlsProvider)
57
63
}
58
64
}
59
65
60
66
extension NIOClientTCPBootstrap {
61
67
/// 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 {
63
74
let bootstrap : NIOClientTCPBootstrap
64
75
#if canImport(Network)
65
76
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
+ }
68
86
} else {
69
87
bootstrap = try ClientBootstrap . makeBootstrap ( on: eventLoop, host: host, requiresTLS: requiresTLS, configuration: configuration)
70
88
}
71
89
#else
72
90
bootstrap = try ClientBootstrap . makeBootstrap ( on: eventLoop, host: host, requiresTLS: requiresTLS, configuration: configuration)
73
91
#endif
74
92
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 {
76
95
return bootstrap. enableTLS ( )
77
96
}
78
97
return bootstrap
79
98
}
80
99
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 {
82
107
return try makeBootstrap ( on: eventLoop, host: host, requiresTLS: requiresTLS, configuration: configuration)
83
108
. channelOption ( ChannelOptions . socket ( SocketOptionLevel ( IPPROTO_TCP) , TCP_NODELAY) , value: 1 )
84
109
. channelInitializer { channel in
0 commit comments