Package io.netty.handler.codec.http2
Class Http2ServerUpgradeCodec
- java.lang.Object
-
- io.netty.handler.codec.http2.Http2ServerUpgradeCodec
-
- All Implemented Interfaces:
HttpServerUpgradeHandler.UpgradeCodec
@UnstableApi public class Http2ServerUpgradeCodec extends java.lang.Object implements HttpServerUpgradeHandler.UpgradeCodec
Server-side codec for performing a cleartext upgrade from HTTP/1.x to HTTP/2.
-
-
Field Summary
Fields Modifier and Type Field Description private Http2ConnectionHandler
connectionHandler
private static ChannelHandler[]
EMPTY_HANDLERS
private Http2FrameReader
frameReader
private java.lang.String
handlerName
private ChannelHandler[]
handlers
private static InternalLogger
logger
private static java.util.List<java.lang.CharSequence>
REQUIRED_UPGRADE_HEADERS
private Http2Settings
settings
-
Constructor Summary
Constructors Modifier Constructor Description Http2ServerUpgradeCodec(Http2ConnectionHandler connectionHandler)
Creates the codec using a default name for the connection handler when adding to the pipeline.Http2ServerUpgradeCodec(Http2FrameCodec http2Codec, ChannelHandler... handlers)
Creates the codec using a default name for the connection handler when adding to the pipeline.Http2ServerUpgradeCodec(Http2MultiplexCodec http2Codec)
Creates the codec using a default name for the connection handler when adding to the pipeline.Http2ServerUpgradeCodec(java.lang.String handlerName, Http2ConnectionHandler connectionHandler)
Creates the codec providing an upgrade to the given handler for HTTP/2.private
Http2ServerUpgradeCodec(java.lang.String handlerName, Http2ConnectionHandler connectionHandler, ChannelHandler... handlers)
Http2ServerUpgradeCodec(java.lang.String handlerName, Http2MultiplexCodec http2Codec)
Creates the codec providing an upgrade to the given handler for HTTP/2.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static ByteBuf
createSettingsFrame(ChannelHandlerContext ctx, ByteBuf payload)
Creates an HTTP2-Settings header with the given payload.private Http2Settings
decodeSettings(ChannelHandlerContext ctx, ByteBuf frame)
Decodes the settings frame and returns the settings.private Http2Settings
decodeSettingsHeader(ChannelHandlerContext ctx, java.lang.CharSequence settingsHeader)
Decodes the settings header and returns aHttp2Settings
object.boolean
prepareUpgradeResponse(ChannelHandlerContext ctx, FullHttpRequest upgradeRequest, HttpHeaders headers)
Prepares theupgradeHeaders
for a protocol update based upon the contents ofupgradeRequest
.java.util.Collection<java.lang.CharSequence>
requiredUpgradeHeaders()
Gets all protocol-specific headers required by this protocol for a successful upgrade.void
upgradeTo(ChannelHandlerContext ctx, FullHttpRequest upgradeRequest)
Performs an HTTP protocol upgrade from the source codec.
-
-
-
Field Detail
-
logger
private static final InternalLogger logger
-
REQUIRED_UPGRADE_HEADERS
private static final java.util.List<java.lang.CharSequence> REQUIRED_UPGRADE_HEADERS
-
EMPTY_HANDLERS
private static final ChannelHandler[] EMPTY_HANDLERS
-
handlerName
private final java.lang.String handlerName
-
connectionHandler
private final Http2ConnectionHandler connectionHandler
-
handlers
private final ChannelHandler[] handlers
-
frameReader
private final Http2FrameReader frameReader
-
settings
private Http2Settings settings
-
-
Constructor Detail
-
Http2ServerUpgradeCodec
public Http2ServerUpgradeCodec(Http2ConnectionHandler connectionHandler)
Creates the codec using a default name for the connection handler when adding to the pipeline.- Parameters:
connectionHandler
- the HTTP/2 connection handler
-
Http2ServerUpgradeCodec
public Http2ServerUpgradeCodec(Http2MultiplexCodec http2Codec)
Creates the codec using a default name for the connection handler when adding to the pipeline.- Parameters:
http2Codec
- the HTTP/2 multiplexing handler.
-
Http2ServerUpgradeCodec
public Http2ServerUpgradeCodec(java.lang.String handlerName, Http2ConnectionHandler connectionHandler)
Creates the codec providing an upgrade to the given handler for HTTP/2.- Parameters:
handlerName
- the name of the HTTP/2 connection handler to be used in the pipeline, ornull
to auto-generate the nameconnectionHandler
- the HTTP/2 connection handler
-
Http2ServerUpgradeCodec
public Http2ServerUpgradeCodec(java.lang.String handlerName, Http2MultiplexCodec http2Codec)
Creates the codec providing an upgrade to the given handler for HTTP/2.- Parameters:
handlerName
- the name of the HTTP/2 connection handler to be used in the pipeline.http2Codec
- the HTTP/2 multiplexing handler.
-
Http2ServerUpgradeCodec
public Http2ServerUpgradeCodec(Http2FrameCodec http2Codec, ChannelHandler... handlers)
Creates the codec using a default name for the connection handler when adding to the pipeline.- Parameters:
http2Codec
- the HTTP/2 frame handler.handlers
- the handlers that will handle theHttp2Frame
s.
-
Http2ServerUpgradeCodec
private Http2ServerUpgradeCodec(java.lang.String handlerName, Http2ConnectionHandler connectionHandler, ChannelHandler... handlers)
-
-
Method Detail
-
requiredUpgradeHeaders
public java.util.Collection<java.lang.CharSequence> requiredUpgradeHeaders()
Description copied from interface:HttpServerUpgradeHandler.UpgradeCodec
Gets all protocol-specific headers required by this protocol for a successful upgrade. Any supplied header will be required to appear in theHttpHeaderNames.CONNECTION
header as well.- Specified by:
requiredUpgradeHeaders
in interfaceHttpServerUpgradeHandler.UpgradeCodec
-
prepareUpgradeResponse
public boolean prepareUpgradeResponse(ChannelHandlerContext ctx, FullHttpRequest upgradeRequest, HttpHeaders headers)
Description copied from interface:HttpServerUpgradeHandler.UpgradeCodec
Prepares theupgradeHeaders
for a protocol update based upon the contents ofupgradeRequest
. This method returns a boolean value to proceed or abort the upgrade in progress. Iffalse
is returned, the upgrade is aborted and theupgradeRequest
will be passed through the inbound pipeline as if no upgrade was performed. Iftrue
is returned, the upgrade will proceed to the next step which invokesHttpServerUpgradeHandler.UpgradeCodec.upgradeTo(io.netty.channel.ChannelHandlerContext, io.netty.handler.codec.http.FullHttpRequest)
. When returningtrue
, you can add headers to theupgradeHeaders
so that they are added to the 101 Switching protocols response.- Specified by:
prepareUpgradeResponse
in interfaceHttpServerUpgradeHandler.UpgradeCodec
-
upgradeTo
public void upgradeTo(ChannelHandlerContext ctx, FullHttpRequest upgradeRequest)
Description copied from interface:HttpServerUpgradeHandler.UpgradeCodec
Performs an HTTP protocol upgrade from the source codec. This method is responsible for adding all handlers required for the new protocol.- Specified by:
upgradeTo
in interfaceHttpServerUpgradeHandler.UpgradeCodec
- Parameters:
ctx
- the context for the current handler.upgradeRequest
- the request that triggered the upgrade to this protocol.
-
decodeSettingsHeader
private Http2Settings decodeSettingsHeader(ChannelHandlerContext ctx, java.lang.CharSequence settingsHeader) throws Http2Exception
Decodes the settings header and returns aHttp2Settings
object.- Throws:
Http2Exception
-
decodeSettings
private Http2Settings decodeSettings(ChannelHandlerContext ctx, ByteBuf frame) throws Http2Exception
Decodes the settings frame and returns the settings.- Throws:
Http2Exception
-
createSettingsFrame
private static ByteBuf createSettingsFrame(ChannelHandlerContext ctx, ByteBuf payload)
Creates an HTTP2-Settings header with the given payload. The payload buffer is released.
-
-