ApplicationProtocolNegotiationHandler
A helper ChannelInboundHandler
that makes it easy to swap channel pipelines based on the result of an ALPN negotiation.
final class ApplicationProtocolNegotiationHandler
The standard pattern used by applications that want to use ALPN is to select an application protocol based on the result, optionally falling back to some default protocol. To do this in SwiftNIO requires that the channel pipeline be reconfigured based on the result of the ALPN negotiation. This channel handler encapsulates that logic in a generic form that doesn’t depend on the specific TLS implementation in use by using TLSUserEvent
The user of this channel handler provides a single closure that is called with an ALPNResult
when the ALPN negotiation is complete. Based on that result the user is free to reconfigure the ChannelPipeline
as required, and should return an EventLoopFuture
that will complete when the pipeline is reconfigured.
Until the EventLoopFuture
completes, this channel handler will buffer inbound data. When the EventLoopFuture
completes, the buffered data will be replayed down the channel. Then, finally, this channel handler will automatically remove itself from the channel pipeline, leaving the pipeline in its final configuration.
Citizens in NIOTLS
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(alpnCompleteHandler: @escaping (ALPNResult, Channel) -> EventLoopFuture<Void>
) Create an
ApplicationProtocolNegotiationHandler
with the given completion callback.init(alpnCompleteHandler: @escaping (ALPNResult) -> EventLoopFuture<Void>
) Create an
ApplicationProtocolNegotiationHandler
with the given completion callback.
Instance members
func channelInactive(context: ChannelHandlerContext
) func channelRead(context: ChannelHandlerContext, data: NIOAny
) func userInboundEventTriggered(context: ChannelHandlerContext, event: Any
)
Instance features
func channelActive(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 handlerAdded(context: ChannelHandlerContext
) Do nothing by default.
func handlerRemoved(context: ChannelHandlerContext
) Do nothing by default.
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 wrapInboundOut(InboundOut
) -> NIOAny func wrapOutboundOut(OutboundOut
) -> NIOAny