From 81cda8c5dddd3677c0e7b77145c28ace88a0bede Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Mon, 29 Apr 2024 11:24:36 +0100 Subject: [PATCH] Update for non-generic HTTPChannelBuilder (#59) * Update for non-generic HTTPChannelBuilder * Update for HB 2.0 beta 3 * Use 2.0.0 beta 4 --- Package.swift | 2 +- .../WebSocketHTTPChannelBuilder.swift | 4 ++-- Sources/HummingbirdWebSocket/WebSocketRouter.swift | 2 +- .../WebSocketExtensionTests.swift | 2 +- Tests/HummingbirdWebSocketTests/WebSocketTests.swift | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Package.swift b/Package.swift index 3fd16b2..e601b41 100644 --- a/Package.swift +++ b/Package.swift @@ -12,7 +12,7 @@ let package = Package( .library(name: "HummingbirdWSCompression", targets: ["HummingbirdWSCompression"]), ], dependencies: [ - .package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0-beta.2"), + .package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0-beta.4"), .package(url: "https://github.com/apple/swift-http-types.git", from: "1.0.0"), .package(url: "https://github.com/apple/swift-log.git", from: "1.4.0"), .package(url: "https://github.com/apple/swift-nio.git", from: "2.62.0"), diff --git a/Sources/HummingbirdWebSocket/WebSocketHTTPChannelBuilder.swift b/Sources/HummingbirdWebSocket/WebSocketHTTPChannelBuilder.swift index 38a4658..79bb16a 100644 --- a/Sources/HummingbirdWebSocket/WebSocketHTTPChannelBuilder.swift +++ b/Sources/HummingbirdWebSocket/WebSocketHTTPChannelBuilder.swift @@ -26,7 +26,7 @@ extension HTTPChannelBuilder { configuration: WebSocketServerConfiguration = .init(), additionalChannelHandlers: @autoclosure @escaping @Sendable () -> [any RemovableChannelHandler] = [], shouldUpgrade: @escaping @Sendable (HTTPRequest, Channel, Logger) async throws -> ShouldUpgradeResult> - ) -> HTTPChannelBuilder { + ) -> HTTPChannelBuilder { return .init { responder in return HTTP1WebSocketUpgradeChannel( responder: responder, @@ -42,7 +42,7 @@ extension HTTPChannelBuilder { configuration: WebSocketServerConfiguration = .init(), additionalChannelHandlers: @autoclosure @escaping @Sendable () -> [any RemovableChannelHandler] = [], shouldUpgrade: @escaping @Sendable (HTTPRequest, Channel, Logger) throws -> ShouldUpgradeResult> - ) -> HTTPChannelBuilder { + ) -> HTTPChannelBuilder { return .init { responder in return HTTP1WebSocketUpgradeChannel( responder: responder, diff --git a/Sources/HummingbirdWebSocket/WebSocketRouter.swift b/Sources/HummingbirdWebSocket/WebSocketRouter.swift index c7adcbb..2014397 100644 --- a/Sources/HummingbirdWebSocket/WebSocketRouter.swift +++ b/Sources/HummingbirdWebSocket/WebSocketRouter.swift @@ -213,7 +213,7 @@ extension HTTPChannelBuilder { webSocketRouter: WSResponderBuilder, configuration: WebSocketServerConfiguration = .init(), additionalChannelHandlers: @autoclosure @escaping @Sendable () -> [any RemovableChannelHandler] = [] - ) -> HTTPChannelBuilder where WSResponderBuilder.Responder.Context: WebSocketRequestContext { + ) -> HTTPChannelBuilder where WSResponderBuilder.Responder.Context: WebSocketRequestContext { let webSocketReponder = webSocketRouter.buildResponder() return .init { responder in return HTTP1WebSocketUpgradeChannel( diff --git a/Tests/HummingbirdWebSocketTests/WebSocketExtensionTests.swift b/Tests/HummingbirdWebSocketTests/WebSocketExtensionTests.swift index 68fb2db..a16b243 100644 --- a/Tests/HummingbirdWebSocketTests/WebSocketExtensionTests.swift +++ b/Tests/HummingbirdWebSocketTests/WebSocketExtensionTests.swift @@ -26,7 +26,7 @@ import XCTest final class HummingbirdWebSocketExtensionTests: XCTestCase { func testClientAndServer( - serverChannel: HTTPChannelBuilder, + serverChannel: HTTPChannelBuilder, clientExtensions: [WebSocketExtensionFactory] = [], client clientHandler: @escaping WebSocketDataHandler ) async throws { diff --git a/Tests/HummingbirdWebSocketTests/WebSocketTests.swift b/Tests/HummingbirdWebSocketTests/WebSocketTests.swift index 4a9dfee..880c3c8 100644 --- a/Tests/HummingbirdWebSocketTests/WebSocketTests.swift +++ b/Tests/HummingbirdWebSocketTests/WebSocketTests.swift @@ -77,7 +77,7 @@ final class HummingbirdWebSocketTests: XCTestCase { } @discardableResult func testClientAndServer( - serverChannel: HTTPChannelBuilder, + serverChannel: HTTPChannelBuilder, getClient: @escaping @Sendable (Int, Logger) throws -> WebSocketClient ) async throws -> WebSocketCloseFrame? { try await withThrowingTaskGroup(of: Void.self) { group in @@ -129,7 +129,7 @@ final class HummingbirdWebSocketTests: XCTestCase { shouldUpgrade: @escaping @Sendable (HTTPRequest) throws -> HTTPFields? = { _ in return [:] }, getClient: @escaping @Sendable (Int, Logger) throws -> WebSocketClient ) async throws -> WebSocketCloseFrame? { - let webSocketUpgrade: HTTPChannelBuilder = .http1WebSocketUpgrade { head, _, _ in + let webSocketUpgrade: HTTPChannelBuilder = .http1WebSocketUpgrade { head, _, _ in if let headers = try shouldUpgrade(head) { return .upgrade(headers, serverHandler) } else { @@ -173,7 +173,7 @@ final class HummingbirdWebSocketTests: XCTestCase { webSocketRouter: Router, getClient: @escaping @Sendable (Int, Logger) throws -> WebSocketClient ) async throws -> WebSocketCloseFrame? { - let webSocketUpgrade: HTTPChannelBuilder = .http1WebSocketUpgrade(webSocketRouter: webSocketRouter) + let webSocketUpgrade: HTTPChannelBuilder = .http1WebSocketUpgrade(webSocketRouter: webSocketRouter) return try await self.testClientAndServer( serverChannel: webSocketUpgrade, getClient: getClient @@ -540,7 +540,7 @@ final class HummingbirdWebSocketTests: XCTestCase { router.ws("/ws") { inbound, _, _ in for try await _ in inbound {} } - let webSocketUpgrade: HTTPChannelBuilder = .http1WebSocketUpgrade( + let webSocketUpgrade: HTTPChannelBuilder = .http1WebSocketUpgrade( webSocketRouter: router, configuration: .init(autoPing: .enabled(timePeriod: .milliseconds(50))) )