GeezerVison is showing netty.io — HttpServerUpgradeHandler (Netty API Reference (4.1.141.Final))
Class HttpServerUpgradeHandler
- All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler
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
The source codec that is used in the pipeline initially.
static interface
A codec that the source can be upgraded to.
static interface
static final class
User event that is fired to notify about the completion of an HTTP upgrade
to another protocol.
-
Constructor Summary
Constructors
Constructor
Description
Constructs the upgrader with the supported codecs.
Constructs the upgrader with the supported codecs.
Constructs the upgrader with the supported codecs.
Constructs the upgrader with the supported codecs.
-
Method Summary
Modifier and Type
Method
Description
Creates a new aggregated message from the specified start message and the specified content.
protected void
Decode from one message to an other.
protected boolean
Determines whether the specified upgrade HttpRequest should be handled by this handler or not.
aggregate, closeAfterContinueResponse, finishAggregation, handleOversizedMessage, ignoreContentAfterContinueResponse, isAggregated, isContentLengthInvalid, isContentMessage, isLastContentMessage, isStartMessage, newContinueResponse
Modifier and Type
Method
Description
protected void
Transfers the information provided by the specified content message to the specified aggregated message.
protected boolean
protected void
Invoked when the specified aggregated message is about to be passed to the next handler in the pipeline.
protected void
Invoked when an incoming request exceeds the maximum content length.
protected boolean
Determine if all objects for the current request/response should be ignored or not.
protected boolean
Returns true if and only if the specified message is already aggregated.
protected boolean
Determine if the message start's content length is known, and if it greater than
maxContentLength.
protected boolean
Returns true if and only if the specified message is a content message.
protected boolean
Returns true if and only if the specified message is the last content message.
protected boolean
Returns true if and only if the specified message is a start message.
Returns the 'continue response' for the specified start message if necessary.
acceptInboundMessage, channelInactive, channelReadComplete, ctx, handlerAdded, handlerRemoved, isHandlingOversizedMessage, maxContentLength, maxCumulationBufferComponents, releaseCurrentMessage, setMaxCumulationBufferComponents
Modifier and Type
Method
Description
boolean
Returns true if the given message should be handled.
void
void
void
Do nothing by default, sub-classes may override this method.
void
Do nothing by default, sub-classes may override this method.
final boolean
Deprecated.
This method will be removed in future releases.
final int
Returns the maximum allowed length of the aggregated message in bytes.
final int
Returns the maximum number of components in the cumulation buffer.
protected final void
final void
Sets the maximum number of components in the cumulation buffer.
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
HttpServerUpgradeHandler
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 initially
upgradeCodecFactory - the factory that creates a new upgrade codec
for one of the requested upgrade protocols
-
HttpServerUpgradeHandler
Constructs the upgrader with the supported codecs.
- Parameters:
sourceCodec - the codec that is being used initially
upgradeCodecFactory - the factory that creates a new upgrade codec
for one of the requested upgrade protocols
maxContentLength - the maximum length of the content of an upgrade request
-
HttpServerUpgradeHandler
Constructs the upgrader with the supported codecs.
- Parameters:
sourceCodec - the codec that is being used initially
upgradeCodecFactory - the factory that creates a new upgrade codec
for one of the requested upgrade protocols
maxContentLength - the maximum length of the content of an upgrade request
validateHeaders - validate the header names and values of the upgrade response.
-
-
Method Details
-
-
beginAggregation
Creates a new aggregated message from the specified start message and the specified content. If the start
message implements ByteBufHolder, its content is appended to the specified content.
This aggregator will continue to append the received content to the specified content.
- Overrides:
beginAggregation in class HttpObjectAggregator
- Throws:
Exception
-
shouldHandleUpgradeRequest
protected boolean shouldHandleUpgradeRequest(HttpRequest req)
Determines whether the specified upgrade HttpRequest should be handled by this handler or not.
This method will be invoked only when the request contains an Upgrade header.
It always returns true by default, which means any request with an Upgrade header
will be handled. You can override this method to ignore certain Upgrade headers, for example:
@Override
protected boolean isUpgradeRequest(HttpRequest req) {
// Do not handle WebSocket upgrades.
return !req.headers().contains(HttpHeaderNames.UPGRADE, "websocket", false);
}
|