Skip to content

Commit 7b7051a

Browse files
Fixed an issue where supplying an empty host to the Client TLS handler would result in an SNI error
Motivation: Testing on Linux seemed to reveal an `NIOSSLExtraError.invalidSNIHostname` error that was thrown when using `https+unix` URLs, which don't have their hostname filled in. The same NIO failure does not occur on macOS, as it seems that Network.framework does not mind an empty hostname. Modifications: Added an extra check to determine if the host is empty before passing it to a `NIOSSLClientHandler`. Result: testHTTPSPlusUNIX() no longer fails on Linux.
1 parent bada1bb commit 7b7051a

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Diff for: Sources/AsyncHTTPClient/HTTPClient.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ extension ChannelPipeline {
665665
let tlsConfiguration = tlsConfiguration ?? TLSConfiguration.forClient()
666666
let context = try NIOSSLContext(configuration: tlsConfiguration)
667667
handlers = [
668-
try NIOSSLClientHandler(context: context, serverHostname: key.host.isIPAddress ? nil : key.host),
668+
try NIOSSLClientHandler(context: context, serverHostname: (key.host.isIPAddress || key.host.isEmpty) ? nil : key.host),
669669
TLSEventsHandler(completionPromise: handshakePromise),
670670
]
671671
} else {

Diff for: Sources/AsyncHTTPClient/Utils.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ extension ClientBootstrap {
6464
} else {
6565
let tlsConfiguration = configuration.tlsConfiguration ?? TLSConfiguration.forClient()
6666
let sslContext = try NIOSSLContext(configuration: tlsConfiguration)
67-
let hostname = (!requiresTLS || host.isIPAddress) ? nil : host
67+
let hostname = (!requiresTLS || host.isIPAddress || host.isEmpty) ? nil : host
6868
let tlsProvider = try NIOSSLClientTLSProvider<ClientBootstrap>(context: sslContext, serverHostname: hostname)
6969
return NIOClientTCPBootstrap(self, tls: tlsProvider)
7070
}

0 commit comments

Comments
 (0)