Skip to content

Commit

Permalink
Fix force try in connect method (#71)
Browse files Browse the repository at this point in the history
* Fail bit more gracefully

* Remove log

* Remove linux tests
  • Loading branch information
jameshartt authored Jul 13, 2020
1 parent 4515d82 commit b073601
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Sources/WebSocketKit/WebSocketClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,18 @@ public final class WebSocketClient {
)

if scheme == "wss" {
let context = try! NIOSSLContext(
configuration: self.configuration.tlsConfiguration ?? .forClient()
)
let tlsHandler = try! NIOSSLClientHandler(context: context, serverHostname: host)
return channel.pipeline.addHandler(tlsHandler).flatMap {
channel.pipeline.addHTTPClientHandlers(leftOverBytesStrategy: .forwardBytes, withClientUpgrade: config)
}.flatMap {
channel.pipeline.addHandler(httpHandler)
do {
let context = try NIOSSLContext(
configuration: self.configuration.tlsConfiguration ?? .forClient()
)
let tlsHandler = try NIOSSLClientHandler(context: context, serverHostname: host)
return channel.pipeline.addHandler(tlsHandler).flatMap {
channel.pipeline.addHTTPClientHandlers(leftOverBytesStrategy: .forwardBytes, withClientUpgrade: config)
}.flatMap {
channel.pipeline.addHandler(httpHandler)
}
} catch {
return channel.pipeline.close(mode: .all)
}
} else {
return channel.pipeline.addHTTPClientHandlers(
Expand Down

0 comments on commit b073601

Please sign in to comment.