Introduce new typed HTTPServerUpgrader and WebSocketServerUpgrader (#2517)

* Introduce new typed `HTTPServerUpgrader` and `WebSocketServerUpgrader`

# Motivation
With our new `NIOAsyncChannel` and typed bootstrap APIs we want to be able to let users spell out their pipeline in a typed way. Pipelines can contain handlers that have to make a forking decision such as HTTP upgrading. Our current `HTTPServerUpgradeHandler` is one of those handlers but it lacks strict typing. To interact nicely with our new typed APIs we need to have a new variant of the `HTTPServerUpgradeHandler` that can carry type information.

# Modification
This PR adds a few things:
1. A new `NIOTypedHTTPServerUpgradeHandler` + `NIOTypedHTTPServeProtocolUpgrader`. I also moved the state handling logic to a separate state machine. I thought about unifying the state machines of the _old_ handler and the new one but they differ in behaviour which makes the state machine more complicated.
2. A new `NIOTypedWebSocketServerUpgrader` that conforms to `NIOTypedHTTPServerProtocolUpgrader`
3. An overhauled WebSocket server example that fully uses Concurrency.

# Result
We now have a way to fully type the server side of HTTP protocol upgrading.

Code review

Update parameter names for new API and fix example

* Introduce new configuration struct and rename to `UpgradablePipeline`

* Review comments
This commit is contained in:
Franz Busch authored and GitHub committed 2023-10-02 07:26:16 -07:00
1 parent 67553a7d6d
commit de07e573d6
10 files changed
+1985 -381

No files matched your search

+1 -1
View File
@@ -146,7 +146,7 @@ private final class WebSocketPingPongHandler: ChannelInboundHandler {
private func pingTestFrameData(context: ChannelHandlerContext) {
let buffer = context.channel.allocator.buffer(string: self.testFrameData)
let frame = WebSocketFrame(fin: true, opcode: .ping, data: buffer)
context.write(self.wrapOutboundOut(frame), promise: nil)
context.writeAndFlush(self.wrapOutboundOut(frame), promise: nil)
}
private func pong(context: ChannelHandlerContext, frame: WebSocketFrame) {