NIOTypedHTTPServerUpgradeHandler
A server-side channel handler that receives HTTP requests and optionally performs an HTTP-upgrade.
NIOTypedHTTPServerUpgradeHandler.swift:78- iOS
- 16+
- macOS
- 13+
- tvOS
- 16+
- watchOS
- 9+
final class NIOTypedHTTPServerUpgradeHandler<UpgradeResult> where UpgradeResult : Sendable
Removes itself from the channel pipeline after the first inbound request on the connection, regardless of whether the upgrade succeeded or not.
This handler behaves a bit differently from its Netty counterpart because it does not allow upgrade on any request but the first on a connection. This is primarily to handle clients that pipeline: it’s sufficiently difficult to ensure that the upgrade happens at a safe time while dealing with pipelined requests that we choose to punt on it entirely and not allow it. As it happens this is mostly fine: the odds of someone needing to upgrade midway through the lifetime of a connection are very low.
Citizens in NIOHTTP1
Conformances
protocol ChannelHandler
Base protocol for handlers that handle I/O events or intercept an I/O operation.
protocol ChannelInboundHandler
ChannelHandler
which handles inbound I/O events for aChannel
.protocol RemovableChannelHandler
A
RemovableChannelHandler
is aChannelHandler
that can be dynamically removed from aChannelPipeline
whilst theChannel
is operating normally. ARemovableChannelHandler
is required to remove itself from theChannelPipeline
(usingChannelHandlerContext.leavePipeline
) as soon as possible.
Show implementation details (2)
Hide implementation details
protocol _ChannelInboundHandler
Untyped
ChannelHandler
which handles inbound I/O events.protocol _EmittingChannelHandler
ChannelHandler which will emit data by calling
ChannelHandlerContext.write
.
Typealiases
Type members
init(httpEncoder: HTTPResponseEncoder, extraHTTPHandlers: [RemovableChannelHandler], upgradeConfiguration: NIOTypedHTTPServerUpgradeConfiguration<UpgradeResult>
) Create a
NIOTypedHTTPServerUpgradeHandler
.
Instance members
var upgradeResultFuture: EventLoopFuture<UpgradeResult>
The upgrade future which will be completed once protocol upgrading has been done.
func channelRead(context: ChannelHandlerContext, data: NIOAny
) func handlerAdded(context: ChannelHandlerContext
) func handlerRemoved(context: ChannelHandlerContext
)
Instance features
func channelActive(context: ChannelHandlerContext
) func channelInactive(context: ChannelHandlerContext
) func channelReadComplete(context: ChannelHandlerContext
) func channelRegistered(context: ChannelHandlerContext
) func channelUnregistered(context: ChannelHandlerContext
) func channelWritabilityChanged(context: ChannelHandlerContext
) func errorCaught(context: ChannelHandlerContext, error: Error
) func removeHandler(context: ChannelHandlerContext, removalToken: ChannelHandlerContext.RemovalToken
) Implements the default behaviour which is to synchronously remove the handler from the pipeline. Thanks to this, stateless
ChannelHandler
s can just useRemovableChannelHandler
as a marker-protocol and declare themselves as removable without writing any extra code.func unwrapInboundIn(NIOAny
) -> InboundIn func userInboundEventTriggered(context: ChannelHandlerContext, event: Any
) func wrapInboundOut(InboundOut
) -> NIOAny func wrapOutboundOut(OutboundOut
) -> NIOAny