Skip to content

Commit 29ea5c3

Browse files
committed
Create NWProtocolTLS.Options on DispatchQueue
1 parent 869ec00 commit 29ea5c3

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

Diff for: Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift

+20-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import Foundation
1818
import Network
19+
import NIO
1920
import NIOSSL
2021
import NIOTransportServices
2122

@@ -58,7 +59,23 @@
5859

5960
/// create NWProtocolTLS.Options for use with NIOTransportServices from the NIOSSL TLSConfiguration
6061
///
61-
/// - Parameter queue: Dispatch queue to run `sec_protocol_options_set_verify_block` on.
62+
/// - Parameter eventLoop: EventLoop to wait for creation of options on
63+
/// - Returns: Future holding NWProtocolTLS Options
64+
func getNWProtocolTLSOptions(on eventLoop: EventLoop) -> EventLoopFuture<NWProtocolTLS.Options> {
65+
let promise = eventLoop.makePromise(of: NWProtocolTLS.Options.self)
66+
Self.tlsDispatchQueue.async {
67+
do {
68+
let options = try self.getNWProtocolTLSOptions()
69+
promise.succeed(options)
70+
} catch {
71+
promise.fail(error)
72+
}
73+
}
74+
return promise.futureResult
75+
}
76+
77+
/// create NWProtocolTLS.Options for use with NIOTransportServices from the NIOSSL TLSConfiguration
78+
///
6279
/// - Returns: Equivalent NWProtocolTLS Options
6380
func getNWProtocolTLSOptions() throws -> NWProtocolTLS.Options {
6481
let options = NWProtocolTLS.Options()
@@ -138,7 +155,8 @@
138155
break
139156
}
140157

141-
precondition(self.certificateVerification != .noHostnameVerification, "TLSConfiguration.certificateVerification = .noHostnameVerification is not supported")
158+
precondition(self.certificateVerification != .noHostnameVerification,
159+
"TLSConfiguration.certificateVerification = .noHostnameVerification is not supported. \(useMTELGExplainer)")
142160

143161
if certificateVerification != .fullVerification || trustRoots != nil {
144162
// add verify block to control certificate verification
@@ -173,13 +191,6 @@
173191
}
174192
}, Self.tlsDispatchQueue
175193
)
176-
177-
case .noHostnameVerification:
178-
precondition(self.certificateVerification != .noHostnameVerification,
179-
"TLSConfiguration.certificateVerification = .noHostnameVerification is not supported. \(useMTELGExplainer)")
180-
181-
case .fullVerification:
182-
break
183194
}
184195
return options
185196
}

Diff for: Sources/AsyncHTTPClient/Utils.swift

+5-3
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,11 @@ extension NIOClientTCPBootstrap {
180180
// if eventLoop is compatible with NIOTransportServices create a NIOTSConnectionBootstrap
181181
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *), let tsBootstrap = NIOTSConnectionBootstrap(validatingGroup: eventLoop) {
182182
// create NIOClientTCPBootstrap with NIOTS TLS provider
183-
let parameters = tlsConfiguration.getNWProtocolTLSOptions()
184-
let tlsProvider = NIOTSClientTLSProvider(tlsOptions: parameters)
185-
return eventLoop.makeSucceededFuture(NIOClientTCPBootstrap(tsBootstrap, tls: tlsProvider))
183+
return tlsConfiguration.getNWProtocolTLSOptions(on: eventLoop)
184+
.map { parameters in
185+
let tlsProvider = NIOTSClientTLSProvider(tlsOptions: parameters)
186+
return NIOClientTCPBootstrap(tsBootstrap, tls: tlsProvider)
187+
}
186188
}
187189
#endif
188190

0 commit comments

Comments
 (0)