-
Notifications
You must be signed in to change notification settings - Fork 125
Support request specific TLS configuration #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
01ff24e
2b11cd6
2beb65f
4111aaa
0a2e939
72b1930
e2e6817
b9e4a34
cb28d0e
22c5f25
b89c92b
ed45320
dabaebb
21a76d1
461be39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import NIOSSL | ||
|
||
/// Wrapper around `TLSConfiguration` from NIOSSL to provide a best effort implementation of `Hashable` | ||
struct BestEffortHashableTLSConfiguration: Hashable { | ||
let base: TLSConfiguration | ||
|
||
init(wrapping base: TLSConfiguration) { | ||
self.base = base | ||
} | ||
|
||
func hash(into hasher: inout Hasher) { | ||
base.bestEffortHash(into: &hasher) | ||
} | ||
|
||
static func == (lhs: BestEffortHashableTLSConfiguration, rhs: BestEffortHashableTLSConfiguration) -> Bool { | ||
lhs.base.bestEffortEquals(rhs.base) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,12 +139,16 @@ final class ConnectionPool { | |
self.port = request.port | ||
self.host = request.host | ||
self.unixPath = request.socketPath | ||
if let tls = request.tlsConfiguration { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @artemredkin should we add a test case that targets the pool directly here? Ie no actual connections? |
||
self.tlsConfiguration = BestEffortHashableTLSConfiguration(wrapping: tls) | ||
} | ||
} | ||
|
||
var scheme: Scheme | ||
var host: String | ||
var port: Int | ||
var unixPath: String | ||
var tlsConfiguration: BestEffortHashableTLSConfiguration? | ||
|
||
enum Scheme: Hashable { | ||
case http | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,17 +150,22 @@ extension NIOClientTCPBootstrap { | |
let key = destination | ||
|
||
let requiresTLS = key.scheme.requiresTLS | ||
// Override optional connection pool configuration. | ||
var keyConfiguration = configuration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm finding the naming here somewhat confusing: keyConfiguration is not derived from the key but from I think it'd be nice to wrap this logic up into something written as a function that clarifies what it does (merges config from two sources, preferring config in the I'm also a bit uncertain as to why this is necessary. Why isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, should this merge perhaps be done at a higher level, say when we create the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I moved the actual configuration "generation" to the place where we initialize the connection provider as you suggested, and added |
||
if let tlsConfiguration = key.tlsConfiguration { | ||
keyConfiguration.tlsConfiguration = tlsConfiguration.base | ||
} | ||
let bootstrap: NIOClientTCPBootstrap | ||
do { | ||
bootstrap = try NIOClientTCPBootstrap.makeHTTPClientBootstrapBase(on: channelEventLoop, host: key.host, port: key.port, requiresTLS: requiresTLS, configuration: configuration) | ||
bootstrap = try NIOClientTCPBootstrap.makeHTTPClientBootstrapBase(on: channelEventLoop, host: key.host, port: key.port, requiresTLS: requiresTLS, configuration: keyConfiguration) | ||
} catch { | ||
return channelEventLoop.makeFailedFuture(error) | ||
} | ||
|
||
let channel: EventLoopFuture<Channel> | ||
switch key.scheme { | ||
case .http, .https: | ||
let address = HTTPClient.resolveAddress(host: key.host, port: key.port, proxy: configuration.proxy) | ||
let address = HTTPClient.resolveAddress(host: key.host, port: key.port, proxy: keyConfiguration.proxy) | ||
channel = bootstrap.connect(host: address.host, port: address.port) | ||
case .unix, .http_unix, .https_unix: | ||
channel = bootstrap.connect(unixDomainSocketPath: key.unixPath) | ||
|
@@ -173,7 +178,7 @@ extension NIOClientTCPBootstrap { | |
|
||
if requiresLateSSLHandler { | ||
let handshakePromise = channel.eventLoop.makePromise(of: Void.self) | ||
channel.pipeline.syncAddLateSSLHandlerIfNeeded(for: key, tlsConfiguration: configuration.tlsConfiguration, handshakePromise: handshakePromise) | ||
channel.pipeline.syncAddLateSSLHandlerIfNeeded(for: key, tlsConfiguration: keyConfiguration.tlsConfiguration, handshakePromise: handshakePromise) | ||
handshakeFuture = handshakePromise.futureResult | ||
} else if requiresTLS { | ||
do { | ||
|
Uh oh!
There was an error while loading. Please reload this page.