Top Description Inners Fields Constructors Methods
io.netty5.handler.codec.http

public Class HttpClientUpgradeHandler<C extends io.netty5.handler.codec.http.HttpContent<C>>

extends HttpObjectAggregator<C extends HttpContent<C>>
Class Inheritance
Imports
io.netty5.channel.internal.DelegatingChannelHandlerContext, io.netty5.util.Send, .AsciiString, io.netty5.channel.ChannelHandlerContext, io.netty5.util.concurrent.Future, java.util.Collection, .LinkedHashSet, .Set

Client-side handler for handling an HTTP upgrade handshake to another protocol. When the first HTTP request is sent, this handler will add all appropriate headers to perform an upgrade to the new protocol. If the upgrade fails (i.e. response is not 101 Switching Protocols), this handler simply removes itself from the pipeline. If the upgrade is successful, upgrades the pipeline to the new protocol.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
HttpClientUpgradeHandler.SourceCodec

The source codec that is used in the pipeline initially.

public static interface
HttpClientUpgradeHandler.UpgradeCodec

A codec that the source can be upgraded to.

public static enum
HttpClientUpgradeHandler.UpgradeEvent

User events that are fired to notify about upgrade status.

Field Summary

Modifier and TypeField and Description
private final HttpClientUpgradeHandler.SourceCodec
private final HttpClientUpgradeHandler.UpgradeCodec
private boolean

Constructor Summary

AccessConstructor and Description
public
HttpClientUpgradeHandler(HttpClientUpgradeHandler.SourceCodec
the codec that is being used initially.
sourceCodec
,
HttpClientUpgradeHandler.UpgradeCodec
the codec that the client would like to upgrade to.
upgradeCodec
,
int
the maximum length of the aggregated content.
maxContentLength
)

Constructs the client upgrade handler.

Method Summary

Modifier and TypeMethod and Description
protected void
decode(final ChannelHandlerContext ctx, HttpObject
the message to decode to another one
msg
)

Overrides io.netty5.handler.codec.MessageAggregator.decode.

Decode from one message to another.
private static void
private void
setUpgradeRequestHeaders(ChannelHandlerContext ctx, HttpRequest request)

Adds all upgrade request headers necessary for an upgrade to the supported protocols.

private void
public Future<Void>
write(ChannelHandlerContext
the ChannelHandlerContext for which the write operation is made
ctx
,
Object
the message to write
msg
)

Overrides default io.netty5.channel.ChannelHandler.write.

Called once a write operation is made.
Inherited from io.netty5.handler.codec.http.HttpObjectAggregator:
aggregatebeginAggregationchannelExceptionCaughtcloseAfterContinueResponsefinishAggregationhandleOversizedMessageignoreContentAfterContinueResponseisAggregatedisContentLengthInvalidisLastContentMessagelengthForAggregationlengthForContentnewContinueResponsetryContentMessagetryStartMessage

Field Detail

sourceCodecback to summary
private final HttpClientUpgradeHandler.SourceCodec sourceCodec
upgradeCodecback to summary
private final HttpClientUpgradeHandler.UpgradeCodec upgradeCodec
upgradeRequestedback to summary
private boolean upgradeRequested

Constructor Detail

HttpClientUpgradeHandlerback to summary
public HttpClientUpgradeHandler(HttpClientUpgradeHandler.SourceCodec sourceCodec, HttpClientUpgradeHandler.UpgradeCodec upgradeCodec, int maxContentLength)

Constructs the client upgrade handler.

Parameters
sourceCodec:HttpClientUpgradeHandler.SourceCodec

the codec that is being used initially.

upgradeCodec:HttpClientUpgradeHandler.UpgradeCodec

the codec that the client would like to upgrade to.

maxContentLength:int

the maximum length of the aggregated content.

Method Detail

decodeback to summary
protected void decode(final ChannelHandlerContext ctx, HttpObject msg) throws Exception

Overrides io.netty5.handler.codec.MessageAggregator.decode.

Doc from io.netty5.handler.codec.MessageToMessageDecoder.decode.

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 be disposed of after this call.

Subclasses that wish to sometimes pass messages through, should instead override the decodeAndClose(ChannelHandlerContext, Object) method.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToMessageDecoder belongs to

msg:HttpObject

the message to decode to another one

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
removeThisHandlerback to summary
private static void removeThisHandler(ChannelHandlerContext ctx)
setUpgradeRequestHeadersback to summary
private void setUpgradeRequestHeaders(ChannelHandlerContext ctx, HttpRequest request)

Adds all upgrade request headers necessary for an upgrade to the supported protocols.

tryUpgradeback to summary
private void tryUpgrade(ChannelHandlerContext ctx, FullHttpResponse response)
writeback to summary
public Future<Void> write(ChannelHandlerContext ctx, Object msg)

Overrides default io.netty5.channel.ChannelHandler.write.

Doc from io.netty5.channel.ChannelHandler.write.

Called once a write operation is made. The write operation will write the messages through the ChannelPipeline. Those are then ready to be flushed to the actual Channel once Channel#flush() is called.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the write operation is made

msg:Object

the message to write

Returns:Future<Void>

the Future which will be notified once the operation completes.

Annotations
@Override
io.netty5.handler.codec.http back to summary

public Interface HttpClientUpgradeHandler.SourceCodec

Known Direct Implementers
io.netty5.handler.codec.http.HttpClientCodec

The source codec that is used in the pipeline initially.

Method Summary

Modifier and TypeMethod and Description
public void
prepareUpgradeFrom(ChannelHandlerContext ctx)

Removes or disables the encoder of this codec so that the UpgradeCodec can send an initial greeting (if any).

public void
upgradeFrom(ChannelHandlerContext ctx)

Removes this codec (i.e. all associated handlers) from the pipeline.

Method Detail

prepareUpgradeFromback to summary
public void prepareUpgradeFrom(ChannelHandlerContext ctx)

Removes or disables the encoder of this codec so that the UpgradeCodec can send an initial greeting (if any).

upgradeFromback to summary
public void upgradeFrom(ChannelHandlerContext ctx)

Removes this codec (i.e. all associated handlers) from the pipeline.

io.netty5.handler.codec.http back to summary

public Interface HttpClientUpgradeHandler.UpgradeCodec


A codec that the source can be upgraded to.

Method Summary

Modifier and TypeMethod and Description
public CharSequence
protocol()

Returns the name of the protocol supported by this codec, as indicated by the 'UPGRADE' header.

public Collection<CharSequence>
setUpgradeHeaders(ChannelHandlerContext ctx, HttpRequest upgradeRequest)

Sets any protocol-specific headers required to the upgrade request.

public void
upgradeTo(ChannelHandlerContext
the context for the current handler.
ctx
,
Send<FullHttpResponse>
the 101 Switching Protocols response that indicates that the server has switched to this protocol.
upgradeResponse
)

Performs an HTTP protocol upgrade from the source codec.

Method Detail

protocolback to summary
public CharSequence protocol()

Returns the name of the protocol supported by this codec, as indicated by the 'UPGRADE' header.

setUpgradeHeadersback to summary
public Collection<CharSequence> setUpgradeHeaders(ChannelHandlerContext ctx, HttpRequest upgradeRequest)

Sets any protocol-specific headers required to the upgrade request. Returns the names of all headers that were added. These headers will be used to populate the CONNECTION header.

upgradeToback to summary
public void upgradeTo(ChannelHandlerContext ctx, Send<FullHttpResponse> upgradeResponse) throws Exception

Performs an HTTP protocol upgrade from the source codec. This method is responsible for adding all handlers required for the new protocol.

Parameters
ctx:ChannelHandlerContext

the context for the current handler.

upgradeResponse:Send<FullHttpResponse>

the 101 Switching Protocols response that indicates that the server has switched to this protocol.

io.netty5.handler.codec.http back to summary

public final Enum HttpClientUpgradeHandler.UpgradeEvent

extends Enum<HttpClientUpgradeHandler.UpgradeEvent>
Class Inheritance

User events that are fired to notify about upgrade status.

Field Summary

Modifier and TypeField and Description
public static final HttpClientUpgradeHandler.UpgradeEvent
UPGRADE_ISSUED

The Upgrade request was sent to the server.

public static final HttpClientUpgradeHandler.UpgradeEvent
UPGRADE_REJECTED

The Upgrade was unsuccessful due to the server not issuing with a 101 Switching Protocols response.

public static final HttpClientUpgradeHandler.UpgradeEvent
UPGRADE_SUCCESSFUL

The Upgrade to the new protocol was successful.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static HttpClientUpgradeHandler.UpgradeEvent
public static HttpClientUpgradeHandler.UpgradeEvent[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

UPGRADE_ISSUEDback to summary
public static final HttpClientUpgradeHandler.UpgradeEvent UPGRADE_ISSUED

The Upgrade request was sent to the server.

UPGRADE_REJECTEDback to summary
public static final HttpClientUpgradeHandler.UpgradeEvent UPGRADE_REJECTED

The Upgrade was unsuccessful due to the server not issuing with a 101 Switching Protocols response.

UPGRADE_SUCCESSFULback to summary
public static final HttpClientUpgradeHandler.UpgradeEvent UPGRADE_SUCCESSFUL

The Upgrade to the new protocol was successful.

Constructor Detail

UpgradeEventback to summary
private UpgradeEvent()

Method Detail

valueOfback to summary
public static HttpClientUpgradeHandler.UpgradeEvent valueOf(String name)
valuesback to summary
public static HttpClientUpgradeHandler.UpgradeEvent[] values()