@@ -50,7 +50,7 @@ public struct WebSocketClient {
5050 }
5151
5252 enum MultiPlatformTLSConfiguration : Sendable {
53- case niossl( TLSConfiguration , serverName : String ? )
53+ case niossl( TLSConfiguration )
5454 #if canImport(Network)
5555 case ts( TSTLSOptions )
5656 #endif
@@ -91,34 +91,7 @@ public struct WebSocketClient {
9191 self . configuration = configuration
9292 self . eventLoopGroup = eventLoopGroup
9393 self . logger = logger
94- self . tlsConfiguration = tlsConfiguration. map { . niossl( $0, serverName: nil ) }
95- }
96-
97- /// Initialize websocket client
98- ///
99- /// - Parametes:
100- /// - url: URL of websocket
101- /// - tlsConfiguration: TLS configuration
102- /// - serverName: Server name indication
103- /// - handler: WebSocket data handler
104- /// - maxFrameSize: Max frame size for a single packet
105- /// - eventLoopGroup: EventLoopGroup to run WebSocket client on
106- /// - logger: Logger
107- public init (
108- url: String ,
109- configuration: WebSocketClientConfiguration = . init( ) ,
110- tlsConfiguration: TLSConfiguration ,
111- serverName: String ,
112- eventLoopGroup: EventLoopGroup = MultiThreadedEventLoopGroup . singleton,
113- logger: Logger ,
114- handler: @escaping WebSocketDataHandler < Context >
115- ) {
116- self . url = . init( url)
117- self . handler = handler
118- self . configuration = configuration
119- self . eventLoopGroup = eventLoopGroup
120- self . logger = logger
121- self . tlsConfiguration = . niossl( tlsConfiguration, serverName: serverName)
94+ self . tlsConfiguration = tlsConfiguration. map { . niossl( $0) }
12295 }
12396
12497 #if canImport(Network)
@@ -156,12 +129,12 @@ public struct WebSocketClient {
156129 let port = self . url. port ?? ( requiresTLS ? 443 : 80 )
157130 if requiresTLS {
158131 switch self . tlsConfiguration {
159- case . niossl( let tlsConfiguration, let serverName ) :
132+ case . niossl( let tlsConfiguration) :
160133 let client = try ClientConnection (
161134 TLSClientChannel (
162135 WebSocketClientChannel ( handler: handler, url: url, configuration: self . configuration) ,
163136 tlsConfiguration: tlsConfiguration,
164- serverHostname: serverName ?? host
137+ serverHostname: self . configuration . sniHostname ?? host
165138 ) ,
166139 address: . hostname( host, port: port) ,
167140 eventLoopGroup: self . eventLoopGroup,
@@ -244,38 +217,6 @@ extension WebSocketClient {
244217 return try await ws. run ( )
245218 }
246219
247- /// Create websocket client, connect and handle connection
248- ///
249- /// - Parametes:
250- /// - url: URL of websocket
251- /// - tlsConfiguration: TLS configuration
252- /// - serverName: Server name indication
253- /// - maxFrameSize: Max frame size for a single packet
254- /// - eventLoopGroup: EventLoopGroup to run WebSocket client on
255- /// - logger: Logger
256- /// - process: Closure handling webSocket
257- /// - Returns: WebSocket close frame details if server returned any
258- @discardableResult public static func connect(
259- url: String ,
260- configuration: WebSocketClientConfiguration = . init( ) ,
261- tlsConfiguration: TLSConfiguration ,
262- serverName: String ,
263- eventLoopGroup: EventLoopGroup = MultiThreadedEventLoopGroup . singleton,
264- logger: Logger ,
265- handler: @escaping WebSocketDataHandler < Context >
266- ) async throws -> WebSocketCloseFrame ? {
267- let ws = self . init (
268- url: url,
269- configuration: configuration,
270- tlsConfiguration: tlsConfiguration,
271- serverName: serverName,
272- eventLoopGroup: eventLoopGroup,
273- logger: logger,
274- handler: handler
275- )
276- return try await ws. run ( )
277- }
278-
279220 #if canImport(Network)
280221 /// Create websocket client, connect and handle connection
281222 ///
0 commit comments