diff --git a/Sources/HummingbirdWebSocket/Server/NIOWebSocketServerUpgrade+ext.swift b/Sources/HummingbirdWebSocket/Server/NIOWebSocketServerUpgrade+ext.swift index 0553024..6cc07d6 100644 --- a/Sources/HummingbirdWebSocket/Server/NIOWebSocketServerUpgrade+ext.swift +++ b/Sources/HummingbirdWebSocket/Server/NIOWebSocketServerUpgrade+ext.swift @@ -22,7 +22,7 @@ import NIOWebSocket /// Should HTTP channel upgrade to WebSocket public enum ShouldUpgradeResult: Sendable { case dontUpgrade - case upgrade(HTTPFields, Value) + case upgrade(HTTPFields = [:], Value) /// Map upgrade result to difference type func map(_ map: (HTTPFields, Value) throws -> (HTTPFields, Result)) rethrows -> ShouldUpgradeResult { diff --git a/Sources/HummingbirdWebSocket/Server/WebSocketRouter.swift b/Sources/HummingbirdWebSocket/Server/WebSocketRouter.swift index 89f8e47..45d0092 100644 --- a/Sources/HummingbirdWebSocket/Server/WebSocketRouter.swift +++ b/Sources/HummingbirdWebSocket/Server/WebSocketRouter.swift @@ -78,7 +78,7 @@ public struct BasicWebSocketRequestContext: WebSocketRequestContext { /// WebSocket upgrade or not public enum RouterShouldUpgrade: Sendable { case dontUpgrade - case upgrade(HTTPFields) + case upgrade(HTTPFields = [:]) } extension RouterMethods { diff --git a/Tests/HummingbirdWebSocketTests/WebSocketTests.swift b/Tests/HummingbirdWebSocketTests/WebSocketTests.swift index b4c3843..46a00db 100644 --- a/Tests/HummingbirdWebSocketTests/WebSocketTests.swift +++ b/Tests/HummingbirdWebSocketTests/WebSocketTests.swift @@ -334,7 +334,7 @@ final class HummingbirdWebSocketTests: XCTestCase { let app = Application( router: router, server: .http1WebSocketUpgrade { _, _, _ in - return .upgrade([:]) { _, outbound, _ in + return .upgrade { _, outbound, _ in try await outbound.write(.text("Hello")) } }, @@ -367,12 +367,12 @@ final class HummingbirdWebSocketTests: XCTestCase { func testRouteSelection() async throws { let router = Router(context: BasicWebSocketRequestContext.self) router.ws("/ws1") { _, _ in - return .upgrade([:]) + return .upgrade() } onUpgrade: { _, outbound, _ in try await outbound.write(.text("One")) } router.ws("/ws2") { _, _ in - return .upgrade([:]) + return .upgrade() } onUpgrade: { _, outbound, _ in try await outbound.write(.text("Two")) } @@ -396,7 +396,7 @@ final class HummingbirdWebSocketTests: XCTestCase { let router = Router(context: BasicWebSocketRequestContext.self) router.ws("/ws") { request, _ in guard request.uri.queryParameters["test"] != nil else { return .dontUpgrade } - return .upgrade([:]) + return .upgrade() } onUpgrade: { _, outbound, context in guard let test = context.request.uri.queryParameters["test"] else { return } try await outbound.write(.text(String(test))) @@ -414,7 +414,7 @@ final class HummingbirdWebSocketTests: XCTestCase { let router = Router(context: BasicWebSocketRequestContext.self) router.group("/ws") .add(middleware: WebSocketUpgradeMiddleware { _, _ in - return .upgrade([:]) + return .upgrade() } onUpgrade: { _, outbound, _ in try await outbound.write(.text("One")) }) @@ -429,7 +429,7 @@ final class HummingbirdWebSocketTests: XCTestCase { func testRouteSelectionFail() async throws { let router = Router(context: BasicWebSocketRequestContext.self) router.ws("/ws") { _, _ in - return .upgrade([:]) + return .upgrade() } onUpgrade: { _, outbound, _ in try await outbound.write(.text("One")) } @@ -463,7 +463,7 @@ final class HummingbirdWebSocketTests: XCTestCase { let router = Router(context: MyRequestContext.self) router.middlewares.add(MyMiddleware()) router.ws("/ws") { _, _ in - return .upgrade([:]) + return .upgrade() } onUpgrade: { _, outbound, context in try await outbound.write(.text(context.requestContext.name)) } @@ -480,7 +480,7 @@ final class HummingbirdWebSocketTests: XCTestCase { func testHTTPRequest() async throws { let router = Router(context: BasicWebSocketRequestContext.self) router.ws("/ws") { _, _ in - return .upgrade([:]) + return .upgrade() } onUpgrade: { _, outbound, _ in try await outbound.write(.text("Hello")) }