Skip to content

Commit d334789

Browse files
committed
TLSEventsHandler wasn't getting added
This fixes testStressGetHttpsSSLError without TS
1 parent 9efc087 commit d334789

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Sources/AsyncHTTPClient/ConnectionPool.swift

+2-5
Original file line numberDiff line numberDiff line change
@@ -419,11 +419,8 @@ final class ConnectionPool {
419419
}
420420

421421
return channel.flatMap { channel -> EventLoopFuture<ConnectionPool.Connection> in
422-
if self.requiresSSLHandler(on: eventLoop) {
423-
channel.pipeline.addSSLHandlerIfNeeded(for: self.key, tlsConfiguration: self.configuration.tlsConfiguration, handshakePromise: handshakePromise)
424-
} else {
425-
handshakePromise.succeed(())
426-
}
422+
423+
channel.pipeline.addSSLHandlerIfNeeded(for: self.key, tlsConfiguration: self.configuration.tlsConfiguration, addSSLClient: self.requiresSSLHandler(on: eventLoop), handshakePromise: handshakePromise)
427424
return handshakePromise.futureResult.flatMap {
428425
channel.pipeline.addHTTPClientHandlers(leftOverBytesStrategy: .forwardBytes)
429426
}.map {

Sources/AsyncHTTPClient/HTTPClient.swift

+12-7
Original file line numberDiff line numberDiff line change
@@ -681,19 +681,24 @@ extension ChannelPipeline {
681681
return addHandlers([encoder, decoder, handler])
682682
}
683683

684-
func addSSLHandlerIfNeeded(for key: ConnectionPool.Key, tlsConfiguration: TLSConfiguration?, handshakePromise: EventLoopPromise<Void>) {
684+
func addSSLHandlerIfNeeded(for key: ConnectionPool.Key, tlsConfiguration: TLSConfiguration?, addSSLClient: Bool, handshakePromise: EventLoopPromise<Void>) {
685685
guard key.scheme == .https else {
686686
handshakePromise.succeed(())
687687
return
688688
}
689689

690690
do {
691-
let tlsConfiguration = tlsConfiguration ?? TLSConfiguration.forClient()
692-
let context = try NIOSSLContext(configuration: tlsConfiguration)
693-
let handlers: [ChannelHandler] = [
694-
try NIOSSLClientHandler(context: context, serverHostname: key.host.isIPAddress ? nil : key.host),
695-
TLSEventsHandler(completionPromise: handshakePromise),
696-
]
691+
let handlers: [ChannelHandler]
692+
if addSSLClient {
693+
let tlsConfiguration = tlsConfiguration ?? TLSConfiguration.forClient()
694+
let context = try NIOSSLContext(configuration: tlsConfiguration)
695+
handlers = [
696+
try NIOSSLClientHandler(context: context, serverHostname: key.host.isIPAddress ? nil : key.host),
697+
TLSEventsHandler(completionPromise: handshakePromise)
698+
]
699+
} else {
700+
handlers = [TLSEventsHandler(completionPromise: handshakePromise)]
701+
}
697702
self.addHandlers(handlers).cascadeFailure(to: handshakePromise)
698703
} catch {
699704
handshakePromise.fail(error)

0 commit comments

Comments
 (0)