Class HttpServerUpgradeHandler<C extends HttpContent<C>>
- java.lang.Object
-
- io.netty5.channel.ChannelHandlerAdapter
-
- io.netty5.handler.codec.MessageToMessageDecoder<I>
-
- io.netty5.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent<C>,FullHttpMessage<?>>
-
- io.netty5.handler.codec.http.HttpObjectAggregator<C>
-
- io.netty5.handler.codec.http.HttpServerUpgradeHandler<C>
-
- All Implemented Interfaces:
ChannelHandler
public class HttpServerUpgradeHandler<C extends HttpContent<C>> extends HttpObjectAggregator<C>
A server-side handler that receives HTTP requests and optionally performs a protocol switch if the requested protocol is supported. Once an upgrade is performed, this handler removes itself from the pipeline.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
HttpServerUpgradeHandler.SourceCodec
The source codec that is used in the pipeline initially.static interface
HttpServerUpgradeHandler.UpgradeCodec
A codec that the source can be upgraded to.static interface
HttpServerUpgradeHandler.UpgradeCodecFactory
Creates a newHttpServerUpgradeHandler.UpgradeCodec
for the requested protocol name.static class
HttpServerUpgradeHandler.UpgradeEvent
User event that is fired to notify about the completion of an HTTP upgrade to another protocol.
-
Constructor Summary
Constructors Constructor Description HttpServerUpgradeHandler(HttpServerUpgradeHandler.SourceCodec sourceCodec, HttpServerUpgradeHandler.UpgradeCodecFactory upgradeCodecFactory)
Constructs the upgrader with the supported codecs.HttpServerUpgradeHandler(HttpServerUpgradeHandler.SourceCodec sourceCodec, HttpServerUpgradeHandler.UpgradeCodecFactory upgradeCodecFactory, int maxContentLength)
Constructs the upgrader with the supported codecs.HttpServerUpgradeHandler(HttpServerUpgradeHandler.SourceCodec sourceCodec, HttpServerUpgradeHandler.UpgradeCodecFactory upgradeCodecFactory, int maxContentLength, boolean validateHeaders)
Constructs the upgrader with the supported codecs.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
decodeAndClose(ChannelHandlerContext ctx, HttpObject msg)
Decode from one message to another.protected boolean
shouldHandleUpgradeRequest(HttpRequest req)
Determines whether the specified upgradeHttpRequest
should be handled by this handler or not.-
Methods inherited from class io.netty5.handler.codec.http.HttpObjectAggregator
aggregate, beginAggregation, channelExceptionCaught, closeAfterContinueResponse, finishAggregation, handleOversizedMessage, ignoreContentAfterContinueResponse, isAggregated, isContentLengthInvalid, isLastContentMessage, lengthForAggregation, lengthForContent, newContinueResponse, tryContentMessage, tryStartMessage
-
Methods inherited from class io.netty5.handler.codec.MessageAggregator
acceptInboundMessage, channelInactive, channelReadComplete, ctx, decode, handlerAdded, handlerRemoved, maxContentLength
-
Methods inherited from class io.netty5.handler.codec.MessageToMessageDecoder
channelRead
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelActive, channelInboundEvent, channelRegistered, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown, write
-
-
-
-
Constructor Detail
-
HttpServerUpgradeHandler
public HttpServerUpgradeHandler(HttpServerUpgradeHandler.SourceCodec sourceCodec, HttpServerUpgradeHandler.UpgradeCodecFactory upgradeCodecFactory)
Constructs the upgrader with the supported codecs.The handler instantiated by this constructor will reject an upgrade request with non-empty content. It should not be a concern because an upgrade request is most likely a GET request. If you have a client that sends a non-GET upgrade request, please consider using
HttpServerUpgradeHandler(SourceCodec, UpgradeCodecFactory, int)
to specify the maximum length of the content of an upgrade request.- Parameters:
sourceCodec
- the codec that is being used initiallyupgradeCodecFactory
- the factory that creates a new upgrade codec for one of the requested upgrade protocols
-
HttpServerUpgradeHandler
public HttpServerUpgradeHandler(HttpServerUpgradeHandler.SourceCodec sourceCodec, HttpServerUpgradeHandler.UpgradeCodecFactory upgradeCodecFactory, int maxContentLength)
Constructs the upgrader with the supported codecs.- Parameters:
sourceCodec
- the codec that is being used initiallyupgradeCodecFactory
- the factory that creates a new upgrade codec for one of the requested upgrade protocolsmaxContentLength
- the maximum length of the content of an upgrade request
-
HttpServerUpgradeHandler
public HttpServerUpgradeHandler(HttpServerUpgradeHandler.SourceCodec sourceCodec, HttpServerUpgradeHandler.UpgradeCodecFactory upgradeCodecFactory, int maxContentLength, boolean validateHeaders)
Constructs the upgrader with the supported codecs.- Parameters:
sourceCodec
- the codec that is being used initiallyupgradeCodecFactory
- the factory that creates a new upgrade codec for one of the requested upgrade protocolsmaxContentLength
- the maximum length of the content of an upgrade requestvalidateHeaders
- validate the header names and values of the upgrade response.
-
-
Method Detail
-
decodeAndClose
protected void decodeAndClose(ChannelHandlerContext ctx, HttpObject msg) throws Exception
Description copied from class:MessageToMessageDecoder
Decode from one message to another. This method will be called for each written message that can be handled by this decoder.The message will not be automatically disposed of after this call. Instead, the responsibility of ensuring that messages are disposed of falls upon the implementor of this method.
Subclasses that wish to have incoming messages automatically disposed of should instead override the
MessageToMessageDecoder.decodeAndClose(ChannelHandlerContext, Object)
method.- Overrides:
decodeAndClose
in classMessageToMessageDecoder<HttpObject>
- Parameters:
ctx
- theChannelHandlerContext
which thisMessageToMessageDecoder
belongs tomsg
- the message to decode to another one- Throws:
Exception
- is thrown if an error occurs
-
shouldHandleUpgradeRequest
protected boolean shouldHandleUpgradeRequest(HttpRequest req)
Determines whether the specified upgradeHttpRequest
should be handled by this handler or not. This method will be invoked only when the request contains anUpgrade
header. It always returnstrue
by default, which means any request with anUpgrade
header will be handled. You can override this method to ignore certainUpgrade
headers, for example:{@code
-
-