diff --git a/Sources/HummingbirdWebSocket/Client/WebSocketClient.swift b/Sources/HummingbirdWebSocket/Client/WebSocketClient.swift index 2aeda18..365dcfe 100644 --- a/Sources/HummingbirdWebSocket/Client/WebSocketClient.swift +++ b/Sources/HummingbirdWebSocket/Client/WebSocketClient.swift @@ -77,7 +77,7 @@ public struct WebSocketClient { eventLoopGroup: EventLoopGroup = MultiThreadedEventLoopGroup.singleton, logger: Logger, handler: @escaping WebSocketDataHandler - ) throws { + ) { self.url = url self.handler = handler self.configuration = configuration @@ -103,7 +103,7 @@ public struct WebSocketClient { eventLoopGroup: NIOTSEventLoopGroup = NIOTSEventLoopGroup.singleton, logger: Logger, handler: @escaping WebSocketDataHandler - ) throws { + ) { self.url = url self.handler = handler self.configuration = configuration @@ -196,7 +196,7 @@ extension WebSocketClient { logger: Logger, handler: @escaping WebSocketDataHandler ) async throws { - let ws = try self.init( + let ws = self.init( url: url, configuration: configuration, tlsConfiguration: tlsConfiguration, @@ -225,7 +225,7 @@ extension WebSocketClient { logger: Logger, handler: @escaping WebSocketDataHandler ) async throws { - let ws = try self.init( + let ws = self.init( url: url, configuration: configuration, transportServicesTLSOptions: transportServicesTLSOptions, diff --git a/Tests/HummingbirdWebSocketTests/WebSocketExtensionTests.swift b/Tests/HummingbirdWebSocketTests/WebSocketExtensionTests.swift index c75784a..455f803 100644 --- a/Tests/HummingbirdWebSocketTests/WebSocketExtensionTests.swift +++ b/Tests/HummingbirdWebSocketTests/WebSocketExtensionTests.swift @@ -61,7 +61,7 @@ final class HummingbirdWebSocketExtensionTests: XCTestCase { } group.addTask { let port = await promise.wait() - let client = try WebSocketClient( + let client = WebSocketClient( url: .init("ws://localhost:\(port)/test"), configuration: .init(extensions: clientExtensions), logger: clientLogger, diff --git a/Tests/HummingbirdWebSocketTests/WebSocketTests.swift b/Tests/HummingbirdWebSocketTests/WebSocketTests.swift index d87ba7c..b4c3843 100644 --- a/Tests/HummingbirdWebSocketTests/WebSocketTests.swift +++ b/Tests/HummingbirdWebSocketTests/WebSocketTests.swift @@ -160,7 +160,7 @@ final class HummingbirdWebSocketTests: XCTestCase { server: serverHandler, shouldUpgrade: shouldUpgrade, getClient: { port, logger in - try WebSocketClient( + WebSocketClient( url: .init("ws://localhost:\(port)"), logger: logger, handler: clientHandler @@ -243,7 +243,7 @@ final class HummingbirdWebSocketTests: XCTestCase { } func testNoConnection() async throws { - let client = try WebSocketClient( + let client = WebSocketClient( url: .init("ws://localhost:10245"), logger: Logger(label: "TestNoConnection") ) { _, _, _ in @@ -260,7 +260,7 @@ final class HummingbirdWebSocketTests: XCTestCase { } getClient: { port, logger in var clientTLSConfiguration = try getClientTLSConfiguration() clientTLSConfiguration.certificateVerification = .none - return try WebSocketClient( + return WebSocketClient( url: .init("wss://localhost:\(port)"), tlsConfiguration: clientTLSConfiguration, logger: logger @@ -279,7 +279,7 @@ final class HummingbirdWebSocketTests: XCTestCase { XCTAssertEqual(head.path, "/ws") return [:] } getClient: { port, logger in - try WebSocketClient( + WebSocketClient( url: .init("ws://localhost:\(port)/ws"), logger: logger ) { _, _, _ in @@ -295,7 +295,7 @@ final class HummingbirdWebSocketTests: XCTestCase { XCTAssertEqual(request.uri.query, "query=parameters&test=true") return [:] } getClient: { port, logger in - try WebSocketClient( + WebSocketClient( url: .init("ws://localhost:\(port)/ws?query=parameters&test=true"), logger: logger ) { _, _, _ in @@ -311,7 +311,7 @@ final class HummingbirdWebSocketTests: XCTestCase { XCTAssertEqual(request.headers[.secWebSocketExtensions], "hb") return [:] } getClient: { port, logger in - try WebSocketClient( + WebSocketClient( url: .init("ws://localhost:\(port)/ws?query=parameters&test=true"), configuration: .init(additionalHeaders: [.secWebSocketExtensions: "hb"]), logger: logger @@ -377,14 +377,14 @@ final class HummingbirdWebSocketTests: XCTestCase { try await outbound.write(.text("Two")) } try await self.testClientAndServerWithRouter(webSocketRouter: router) { port, logger in - try WebSocketClient(url: .init("ws://localhost:\(port)/ws1"), logger: logger) { inbound, _, _ in + WebSocketClient(url: .init("ws://localhost:\(port)/ws1"), logger: logger) { inbound, _, _ in var inboundIterator = inbound.makeAsyncIterator() let msg = try await inboundIterator.next() XCTAssertEqual(msg, .text("One")) } } try await self.testClientAndServerWithRouter(webSocketRouter: router) { port, logger in - try WebSocketClient(url: .init("ws://localhost:\(port)/ws2"), logger: logger) { inbound, _, _ in + WebSocketClient(url: .init("ws://localhost:\(port)/ws2"), logger: logger) { inbound, _, _ in var inboundIterator = inbound.makeAsyncIterator() let msg = try await inboundIterator.next() XCTAssertEqual(msg, .text("Two")) @@ -402,7 +402,7 @@ final class HummingbirdWebSocketTests: XCTestCase { try await outbound.write(.text(String(test))) } try await self.testClientAndServerWithRouter(webSocketRouter: router) { port, logger in - try WebSocketClient(url: .init("ws://localhost:\(port)/ws?test=123"), logger: logger) { inbound, _, _ in + WebSocketClient(url: .init("ws://localhost:\(port)/ws?test=123"), logger: logger) { inbound, _, _ in var inboundIterator = inbound.makeAsyncIterator() let msg = try await inboundIterator.next() XCTAssertEqual(msg, .text("123")) @@ -421,7 +421,7 @@ final class HummingbirdWebSocketTests: XCTestCase { .get { _, _ -> Response in return .init(status: .ok) } do { try await self.testClientAndServerWithRouter(webSocketRouter: router) { port, logger in - try WebSocketClient(url: .init("ws://localhost:\(port)/ws"), logger: logger) { _, _, _ in } + WebSocketClient(url: .init("ws://localhost:\(port)/ws"), logger: logger) { _, _, _ in } } } } @@ -435,7 +435,7 @@ final class HummingbirdWebSocketTests: XCTestCase { } do { try await self.testClientAndServerWithRouter(webSocketRouter: router) { port, logger in - try WebSocketClient(url: .init("ws://localhost:\(port)/not-ws"), logger: logger) { _, _, _ in } + WebSocketClient(url: .init("ws://localhost:\(port)/not-ws"), logger: logger) { _, _, _ in } } } catch let error as WebSocketClientError where error == .webSocketUpgradeFailed {} } @@ -469,7 +469,7 @@ final class HummingbirdWebSocketTests: XCTestCase { } do { try await self.testClientAndServerWithRouter(webSocketRouter: router) { port, logger in - try WebSocketClient(url: .init("ws://localhost:\(port)/ws"), logger: logger) { inbound, _, _ in + WebSocketClient(url: .init("ws://localhost:\(port)/ws"), logger: logger) { inbound, _, _ in let text = try await inbound.first { _ in true } XCTAssertEqual(text, .text("Roger Moore")) } @@ -510,7 +510,7 @@ final class HummingbirdWebSocketTests: XCTestCase { configuration: .init(autoPing: .enabled(timePeriod: .milliseconds(50))) ) try await self.testClientAndServer(serverChannel: webSocketUpgrade) { port, logger in - try WebSocketClient( + WebSocketClient( url: .init("ws://localhost:\(port)/ws"), configuration: .init(additionalHeaders: [.secWebSocketExtensions: "hb"]), logger: logger