hummingbird-project / hummingbird-websocket

Websocket upgrade support for Hummingbird
Apache License 2.0
36 stars 6 forks source link

Websocket 2.x.x #33

Closed adam-fowler closed 7 months ago

adam-fowler commented 8 months ago

All changes are in WebSockets module. All other code is ignored at the moment. Because I haven't implemented a web socket client I haven't added any tests just yet.

let app = HBApplication(
    router: router,
    server: .httpAndWebSocket { channel, head in
        if head.uri == "ws" {
            return .upgrade(HTTPHeaders()) { inbound, outbound, _ in
                for try await packet in inbound {
                    if case .text("disconnect") = packet {
                        break
                    }
                    try await outbound.write(.custom(packet.webSocketFrame))
                }
            }
        } else {
            return .dontUpgrade
        }
    }
)

This is not complete by any measure but gives us an idea what a websocket solution might look like

codecov[bot] commented 8 months ago

Codecov Report

Attention: 320 lines in your changes are missing coverage. Please review.

Comparison is base (397f41e) 85.92% compared to head (64001d4) 0.00%.

Files Patch % Lines
...ources/HummingbirdWebSocket/WebSocketHandler.swift 0.00% 121 Missing :warning:
...birdWebSocket/Server/WebSocketChannelHandler.swift 0.00% 78 Missing :warning:
.../HummingbirdWebSocket/WebSocketInboundStream.swift 0.00% 34 Missing :warning:
...bSocket/Server/NIOWebSocketServerUpgrade+ext.swift 0.00% 26 Missing :warning:
...WebSocket/Server/WebSocketHTTPChannelBuilder.swift 0.00% 22 Missing :warning:
...HummingbirdWebSocket/WebSocketOutboundWriter.swift 0.00% 21 Missing :warning:
...es/HummingbirdWebSocket/WebSocketDataHandler.swift 0.00% 10 Missing :warning:
...ources/HummingbirdWebSocket/WebSocketContext.swift 0.00% 4 Missing :warning:
.../HummingbirdWebSocket/WebSocketFrameSequence.swift 0.00% 4 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## 2.x.x #33 +/- ## ========================================== - Coverage 85.92% 0.00% -85.93% ========================================== Files 11 9 -2 Lines 995 349 -646 ========================================== - Hits 855 0 -855 - Misses 140 349 +209 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.