HTTPServerUpgradeHandler

public class HTTPServerUpgradeHandler : ChannelInboundHandler

A server-side channel handler that receives HTTP requests and optionally performs a HTTP-upgrade. 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.

  • Create a HTTPServerUpgradeHandler.

    Declaration

    Swift

    @available(*, deprecated, message: "Please use init(upgraders:httpEncoder:extraHTTPHandlers:upgradeCompletionHandler:﹚")
    public init(upgraders: [HTTPProtocolUpgrader], httpEncoder: HTTPResponseEncoder?, httpDecoder: HTTPRequestDecoder?, upgradeCompletionHandler: @escaping (ChannelHandlerContext) -> Void)

    Parameters

    upgraders

    All HTTPProtocolUpgrader objects that this pipeline will be able to use to handle HTTP upgrade.

    httpEncoder

    The HTTPResponseEncoder encoding responses from this handler and which will be removed from the pipeline once the upgrade response is sent. This is used mostly to ensure that the pipeline will be in a clean state after upgrade. Pass nil to this parameter if for any reason you want to keep the HTTPResponseEncoder in the pipeline after upgrade.

    httpDecoder

    The HTTPRequestDecoder decoding responses that are passed to this handler. This is necessary to ensure that no further data is parsed as HTTP when we attempt an upgrade. Pass nil to this parameter if for any reason you want to keep the HTTPRequestDecoder in the pipeline after upgrade.

    upgradeCompletionHandler

    A block that will be fired when HTTP upgrade is complete.

  • Create a HTTPServerUpgradeHandler.

    Declaration

    Swift

    public init(upgraders: [HTTPProtocolUpgrader], httpEncoder: HTTPResponseEncoder, extraHTTPHandlers: [ChannelHandler], upgradeCompletionHandler: @escaping (ChannelHandlerContext) -> Void)

    Parameters

    upgraders

    All HTTPProtocolUpgrader objects that this pipeline will be able to use to handle HTTP upgrade.

    httpEncoder

    The HTTPResponseEncoder encoding responses from this handler and which will be removed from the pipeline once the upgrade response is sent. This is used to ensure that the pipeline will be in a clean state after upgrade.

    extraHTTPHandlers

    Any other handlers that are directly related to handling HTTP. At the very least this should include the HTTPDecoder, but should also include any other handler that cannot tolerate receiving non-HTTP data.

    upgradeCompletionHandler

    A block that will be fired when HTTP upgrade is complete.

  • Declaration

    Swift

    public func channelRead(ctx: ChannelHandlerContext, data: NIOAny)