Skip to content

Commit 695a46a

Browse files
committed
Simplified requiresSSLHandler check
1 parent ba87c2e commit 695a46a

File tree

1 file changed

+2
-28
lines changed

1 file changed

+2
-28
lines changed

Sources/AsyncHTTPClient/ConnectionPool.swift

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import Foundation
1616
import NIO
1717
import NIOConcurrencyHelpers
1818
import NIOHTTP1
19-
import NIOSSL
2019
import NIOTransportServices
2120
import NIOTLS
2221

@@ -373,31 +372,6 @@ final class ConnectionPool {
373372
}
374373
}
375374

376-
// if the configuration includes a proxy and requires TLS, TLS will not have been enabled yet. This
377-
// returns whether we need to call addSSLHandlerIfNeeded().
378-
private func requiresSSLHandler(on eventLoop: EventLoop) -> Bool {
379-
// if a proxy is not set return false, otherwise for non-TS situation return true, if TS is available and
380-
// either we don't have an NIOTSEventLoop or the scheme is HTTPS then return true
381-
if self.configuration.proxy != nil {
382-
#if canImport(Network)
383-
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
384-
{
385-
if !(eventLoop is NIOTSEventLoop) {
386-
return true
387-
}
388-
if self.key.scheme == .https {
389-
return true
390-
}
391-
} else {
392-
return true
393-
}
394-
#else
395-
return true
396-
#endif
397-
}
398-
return false
399-
}
400-
401375
private func makeConnection(on eventLoop: EventLoop) -> EventLoopFuture<Connection> {
402376
self.activityPrecondition(expected: [.opened])
403377
let address = HTTPClient.resolveAddress(host: self.key.host, port: self.key.port, proxy: self.configuration.proxy)
@@ -419,8 +393,8 @@ final class ConnectionPool {
419393
}
420394

421395
return channel.flatMap { channel -> EventLoopFuture<ConnectionPool.Connection> in
422-
423-
channel.pipeline.addSSLHandlerIfNeeded(for: self.key, tlsConfiguration: self.configuration.tlsConfiguration, addSSLClient: self.requiresSSLHandler(on: eventLoop), handshakePromise: handshakePromise)
396+
let requiresSSLHandler = self.configuration.proxy != nil && self.key.scheme == .https
397+
channel.pipeline.addSSLHandlerIfNeeded(for: self.key, tlsConfiguration: self.configuration.tlsConfiguration, addSSLClient: requiresSSLHandler, handshakePromise: handshakePromise)
424398
return handshakePromise.futureResult.flatMap {
425399
channel.pipeline.addHTTPClientHandlers(leftOverBytesStrategy: .forwardBytes)
426400
}.map {

0 commit comments

Comments
 (0)