Skip to content

Commit c461c58

Browse files
committed
TLSEventsHandler wasn't getting added
This fixes testStressGetHttpsSSLError without TS
1 parent 1b70ca9 commit c461c58

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Sources/AsyncHTTPClient/ConnectionPool.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,8 @@ final class ConnectionPool {
416416
}
417417

418418
return channel.flatMap { channel -> EventLoopFuture<ConnectionPool.Connection> in
419-
if self.requiresSSLHandler(on: eventLoop) {
420-
channel.pipeline.addSSLHandlerIfNeeded(for: self.key, tlsConfiguration: self.configuration.tlsConfiguration, handshakePromise: handshakePromise)
421-
} else {
422-
handshakePromise.succeed(())
423-
}
419+
420+
channel.pipeline.addSSLHandlerIfNeeded(for: self.key, tlsConfiguration: self.configuration.tlsConfiguration, addSSLClient: self.requiresSSLHandler(on: eventLoop), handshakePromise: handshakePromise)
424421
return handshakePromise.futureResult.flatMap {
425422
channel.pipeline.addHTTPClientHandlers(leftOverBytesStrategy: .forwardBytes)
426423
}.map {

Sources/AsyncHTTPClient/HTTPClient.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -634,19 +634,24 @@ extension ChannelPipeline {
634634
return addHandlers([encoder, decoder, handler])
635635
}
636636

637-
func addSSLHandlerIfNeeded(for key: ConnectionPool.Key, tlsConfiguration: TLSConfiguration?, handshakePromise: EventLoopPromise<Void>) {
637+
func addSSLHandlerIfNeeded(for key: ConnectionPool.Key, tlsConfiguration: TLSConfiguration?, addSSLClient: Bool, handshakePromise: EventLoopPromise<Void>) {
638638
guard key.scheme == .https else {
639639
handshakePromise.succeed(())
640640
return
641641
}
642642

643643
do {
644-
let tlsConfiguration = tlsConfiguration ?? TLSConfiguration.forClient()
645-
let context = try NIOSSLContext(configuration: tlsConfiguration)
646-
let handlers: [ChannelHandler] = [
647-
try NIOSSLClientHandler(context: context, serverHostname: key.host.isIPAddress ? nil : key.host),
648-
TLSEventsHandler(completionPromise: handshakePromise),
649-
]
644+
let handlers: [ChannelHandler]
645+
if addSSLClient {
646+
let tlsConfiguration = tlsConfiguration ?? TLSConfiguration.forClient()
647+
let context = try NIOSSLContext(configuration: tlsConfiguration)
648+
handlers = [
649+
try NIOSSLClientHandler(context: context, serverHostname: key.host.isIPAddress ? nil : key.host),
650+
TLSEventsHandler(completionPromise: handshakePromise)
651+
]
652+
} else {
653+
handlers = [TLSEventsHandler(completionPromise: handshakePromise)]
654+
}
650655
self.addHandlers(handlers).cascadeFailure(to: handshakePromise)
651656
} catch {
652657
handshakePromise.fail(error)

0 commit comments

Comments
 (0)