Package io.netty.handler.codec.spdy
Class SpdyFrameCodec
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.handler.codec.ByteToMessageDecoder
-
- io.netty.handler.codec.spdy.SpdyFrameCodec
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler,io.netty.channel.ChannelOutboundHandler,SpdyFrameDecoderDelegate
public class SpdyFrameCodec extends io.netty.handler.codec.ByteToMessageDecoder implements SpdyFrameDecoderDelegate, io.netty.channel.ChannelOutboundHandler
AChannelHandlerthat encodes and decodes SPDY Frames.
-
-
Field Summary
Fields Modifier and Type Field Description protected static SpdyProtocolExceptionINVALID_FRAMEprotected SpdyFrameDecoderspdyFrameDecoderprotected SpdyFrameEncoderspdyFrameEncoder
-
Constructor Summary
Constructors Modifier Constructor Description SpdyFrameCodec(SpdyVersion version)Creates a new instance with the specifiedversion,validateHeaders (true), and the default decoder and encoder options (maxChunkSize (8192),maxHeaderSize (16384),compressionLevel (6),windowBits (15), andmemLevel (8)).SpdyFrameCodec(SpdyVersion version, boolean validateHeaders)Creates a new instance with the specifiedversion,validateHeaders, and the default decoder and encoder options (maxChunkSize (8192),maxHeaderSize (16384),compressionLevel (6),windowBits (15), andmemLevel (8)).SpdyFrameCodec(SpdyVersion version, int maxChunkSize, int maxHeaderSize, int compressionLevel, int windowBits, int memLevel)Creates a new instance with the specifiedversion,validateHeaders (true), decoder and encoder options.SpdyFrameCodec(SpdyVersion version, int maxChunkSize, int maxHeaderSize, int compressionLevel, int windowBits, int memLevel, boolean validateHeaders)Creates a new instance with the specifiedversion,validateHeaders, decoder and encoder options.SpdyFrameCodec(SpdyVersion version, int maxChunkSize, int maxHeaderSize, int compressionLevel, int windowBits, int memLevel, boolean validateHeaders, boolean supportsUnknownFrames)Creates a new instance with the specifiedversion,validateHeaders, decoder and encoder options.protectedSpdyFrameCodec(SpdyVersion version, int maxChunkSize, SpdyHeaderBlockDecoder spdyHeaderBlockDecoder, SpdyHeaderBlockEncoder spdyHeaderBlockEncoder, boolean validateHeaders)protectedSpdyFrameCodec(SpdyVersion version, int maxChunkSize, SpdyHeaderBlockDecoder spdyHeaderBlockDecoder, SpdyHeaderBlockEncoder spdyHeaderBlockEncoder, boolean validateHeaders, boolean supportsUnknownFrames)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbind(io.netty.channel.ChannelHandlerContext ctx, SocketAddress localAddress, io.netty.channel.ChannelPromise promise)voidchannelReadComplete(io.netty.channel.ChannelHandlerContext ctx)voidclose(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)voidconnect(io.netty.channel.ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, io.netty.channel.ChannelPromise promise)protected SpdyFrameDecodercreateDecoder(SpdyVersion version, SpdyFrameDecoderDelegate delegate, int maxChunkSize)protected SpdyFrameEncodercreateEncoder(SpdyVersion version)protected voiddecode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, List<Object> out)voidderegister(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)voiddisconnect(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)voidflush(io.netty.channel.ChannelHandlerContext ctx)voidhandlerAdded(io.netty.channel.ChannelHandlerContext ctx)protected booleanisValidUnknownFrameHeader(int streamId, int type, byte flags, int length)Check whether the unknown frame is valid, if not, the frame will be discarded, otherwise, the frame will be passed toSpdyFrameDecoder.decodeUnknownFrame(int, byte, int, ByteBuf).protected SpdyFramenewSpdyUnknownFrame(int frameType, byte flags, io.netty.buffer.ByteBuf payload)Create a SpdyUnknownFrame.voidread(io.netty.channel.ChannelHandlerContext ctx)voidreadDataFrame(int streamId, boolean last, io.netty.buffer.ByteBuf data)Called when a DATA frame is received.voidreadFrameError(String message)Called when an unrecoverable session error has occurred.voidreadGoAwayFrame(int lastGoodStreamId, int statusCode)Called when a GOAWAY frame is received.voidreadHeaderBlock(io.netty.buffer.ByteBuf headerBlock)Called when the header block within a SYN_STREAM, SYN_REPLY, or HEADERS frame is received.voidreadHeaderBlockEnd()Called when an entire header block has been received.voidreadHeadersFrame(int streamId, boolean last)Called when a HEADERS frame is received.voidreadPingFrame(int id)Called when a PING frame is received.voidreadRstStreamFrame(int streamId, int statusCode)Called when a RST_STREAM frame is received.voidreadSetting(int id, int value, boolean persistValue, boolean persisted)Called when an individual setting within a SETTINGS frame is received.voidreadSettingsEnd()Called when the entire SETTINGS frame has been received.voidreadSettingsFrame(boolean clearPersisted)Called when a SETTINGS frame is received.voidreadSynReplyFrame(int streamId, boolean last)Called when a SYN_REPLY frame is received.voidreadSynStreamFrame(int streamId, int associatedToStreamId, byte priority, boolean last, boolean unidirectional)Called when a SYN_STREAM frame is received.voidreadUnknownFrame(int frameType, byte flags, io.netty.buffer.ByteBuf payload)Called when an unknown frame is received.voidreadWindowUpdateFrame(int streamId, int deltaWindowSize)Called when a WINDOW_UPDATE frame is received.voidwrite(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)-
Methods inherited from class io.netty.handler.codec.ByteToMessageDecoder
actualReadableBytes, callDecode, channelInactive, channelRead, decodeLast, discardSomeReadBytes, handlerRemoved, handlerRemoved0, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught
-
-
-
-
Field Detail
-
INVALID_FRAME
protected static final SpdyProtocolException INVALID_FRAME
-
spdyFrameDecoder
protected final SpdyFrameDecoder spdyFrameDecoder
-
spdyFrameEncoder
protected final SpdyFrameEncoder spdyFrameEncoder
-
-
Constructor Detail
-
SpdyFrameCodec
public SpdyFrameCodec(SpdyVersion version)
Creates a new instance with the specifiedversion,validateHeaders (true), and the default decoder and encoder options (maxChunkSize (8192),maxHeaderSize (16384),compressionLevel (6),windowBits (15), andmemLevel (8)).
-
SpdyFrameCodec
public SpdyFrameCodec(SpdyVersion version, boolean validateHeaders)
Creates a new instance with the specifiedversion,validateHeaders, and the default decoder and encoder options (maxChunkSize (8192),maxHeaderSize (16384),compressionLevel (6),windowBits (15), andmemLevel (8)).
-
SpdyFrameCodec
public SpdyFrameCodec(SpdyVersion version, int maxChunkSize, int maxHeaderSize, int compressionLevel, int windowBits, int memLevel)
Creates a new instance with the specifiedversion,validateHeaders (true), decoder and encoder options.
-
SpdyFrameCodec
public SpdyFrameCodec(SpdyVersion version, int maxChunkSize, int maxHeaderSize, int compressionLevel, int windowBits, int memLevel, boolean validateHeaders)
Creates a new instance with the specifiedversion,validateHeaders, decoder and encoder options.
-
SpdyFrameCodec
public SpdyFrameCodec(SpdyVersion version, int maxChunkSize, int maxHeaderSize, int compressionLevel, int windowBits, int memLevel, boolean validateHeaders, boolean supportsUnknownFrames)
Creates a new instance with the specifiedversion,validateHeaders, decoder and encoder options.
-
SpdyFrameCodec
protected SpdyFrameCodec(SpdyVersion version, int maxChunkSize, SpdyHeaderBlockDecoder spdyHeaderBlockDecoder, SpdyHeaderBlockEncoder spdyHeaderBlockEncoder, boolean validateHeaders)
-
SpdyFrameCodec
protected SpdyFrameCodec(SpdyVersion version, int maxChunkSize, SpdyHeaderBlockDecoder spdyHeaderBlockDecoder, SpdyHeaderBlockEncoder spdyHeaderBlockEncoder, boolean validateHeaders, boolean supportsUnknownFrames)
-
-
Method Detail
-
createDecoder
protected SpdyFrameDecoder createDecoder(SpdyVersion version, SpdyFrameDecoderDelegate delegate, int maxChunkSize)
-
createEncoder
protected SpdyFrameEncoder createEncoder(SpdyVersion version)
-
handlerAdded
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
handlerAddedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerAddedin classio.netty.channel.ChannelHandlerAdapter- Throws:
Exception
-
decode
protected void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, List<Object> out) throws Exception- Specified by:
decodein classio.netty.handler.codec.ByteToMessageDecoder- Throws:
Exception
-
channelReadComplete
public void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelReadCompletein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadCompletein classio.netty.handler.codec.ByteToMessageDecoder- Throws:
Exception
-
bind
public void bind(io.netty.channel.ChannelHandlerContext ctx, SocketAddress localAddress, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
bindin interfaceio.netty.channel.ChannelOutboundHandler- Throws:
Exception
-
connect
public void connect(io.netty.channel.ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
connectin interfaceio.netty.channel.ChannelOutboundHandler- Throws:
Exception
-
disconnect
public void disconnect(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
disconnectin interfaceio.netty.channel.ChannelOutboundHandler- Throws:
Exception
-
close
public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
closein interfaceio.netty.channel.ChannelOutboundHandler- Throws:
Exception
-
deregister
public void deregister(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
deregisterin interfaceio.netty.channel.ChannelOutboundHandler- Throws:
Exception
-
read
public void read(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
readin interfaceio.netty.channel.ChannelOutboundHandler- Throws:
Exception
-
flush
public void flush(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
flushin interfaceio.netty.channel.ChannelOutboundHandler- Throws:
Exception
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
writein interfaceio.netty.channel.ChannelOutboundHandler- Throws:
Exception
-
readDataFrame
public void readDataFrame(int streamId, boolean last, io.netty.buffer.ByteBuf data)Description copied from interface:SpdyFrameDecoderDelegateCalled when a DATA frame is received.- Specified by:
readDataFramein interfaceSpdyFrameDecoderDelegate
-
readSynStreamFrame
public void readSynStreamFrame(int streamId, int associatedToStreamId, byte priority, boolean last, boolean unidirectional)Description copied from interface:SpdyFrameDecoderDelegateCalled when a SYN_STREAM frame is received. The Name/Value Header Block is not included. See readHeaderBlock().- Specified by:
readSynStreamFramein interfaceSpdyFrameDecoderDelegate
-
readSynReplyFrame
public void readSynReplyFrame(int streamId, boolean last)Description copied from interface:SpdyFrameDecoderDelegateCalled when a SYN_REPLY frame is received. The Name/Value Header Block is not included. See readHeaderBlock().- Specified by:
readSynReplyFramein interfaceSpdyFrameDecoderDelegate
-
readRstStreamFrame
public void readRstStreamFrame(int streamId, int statusCode)Description copied from interface:SpdyFrameDecoderDelegateCalled when a RST_STREAM frame is received.- Specified by:
readRstStreamFramein interfaceSpdyFrameDecoderDelegate
-
readSettingsFrame
public void readSettingsFrame(boolean clearPersisted)
Description copied from interface:SpdyFrameDecoderDelegateCalled when a SETTINGS frame is received. Settings are not included. See readSetting().- Specified by:
readSettingsFramein interfaceSpdyFrameDecoderDelegate
-
readSetting
public void readSetting(int id, int value, boolean persistValue, boolean persisted)Description copied from interface:SpdyFrameDecoderDelegateCalled when an individual setting within a SETTINGS frame is received.- Specified by:
readSettingin interfaceSpdyFrameDecoderDelegate
-
readSettingsEnd
public void readSettingsEnd()
Description copied from interface:SpdyFrameDecoderDelegateCalled when the entire SETTINGS frame has been received.- Specified by:
readSettingsEndin interfaceSpdyFrameDecoderDelegate
-
readPingFrame
public void readPingFrame(int id)
Description copied from interface:SpdyFrameDecoderDelegateCalled when a PING frame is received.- Specified by:
readPingFramein interfaceSpdyFrameDecoderDelegate
-
readGoAwayFrame
public void readGoAwayFrame(int lastGoodStreamId, int statusCode)Description copied from interface:SpdyFrameDecoderDelegateCalled when a GOAWAY frame is received.- Specified by:
readGoAwayFramein interfaceSpdyFrameDecoderDelegate
-
readHeadersFrame
public void readHeadersFrame(int streamId, boolean last)Description copied from interface:SpdyFrameDecoderDelegateCalled when a HEADERS frame is received. The Name/Value Header Block is not included. See readHeaderBlock().- Specified by:
readHeadersFramein interfaceSpdyFrameDecoderDelegate
-
readWindowUpdateFrame
public void readWindowUpdateFrame(int streamId, int deltaWindowSize)Description copied from interface:SpdyFrameDecoderDelegateCalled when a WINDOW_UPDATE frame is received.- Specified by:
readWindowUpdateFramein interfaceSpdyFrameDecoderDelegate
-
readHeaderBlock
public void readHeaderBlock(io.netty.buffer.ByteBuf headerBlock)
Description copied from interface:SpdyFrameDecoderDelegateCalled when the header block within a SYN_STREAM, SYN_REPLY, or HEADERS frame is received.- Specified by:
readHeaderBlockin interfaceSpdyFrameDecoderDelegate
-
readHeaderBlockEnd
public void readHeaderBlockEnd()
Description copied from interface:SpdyFrameDecoderDelegateCalled when an entire header block has been received.- Specified by:
readHeaderBlockEndin interfaceSpdyFrameDecoderDelegate
-
readUnknownFrame
public void readUnknownFrame(int frameType, byte flags, io.netty.buffer.ByteBuf payload)Description copied from interface:SpdyFrameDecoderDelegateCalled when an unknown frame is received.- Specified by:
readUnknownFramein interfaceSpdyFrameDecoderDelegate- Parameters:
frameType- the frame type from the spdy header.flags- the flags in the frame header.payload- the payload of the frame.
-
newSpdyUnknownFrame
protected SpdyFrame newSpdyUnknownFrame(int frameType, byte flags, io.netty.buffer.ByteBuf payload)
Create a SpdyUnknownFrame.
-
isValidUnknownFrameHeader
protected boolean isValidUnknownFrameHeader(int streamId, int type, byte flags, int length)Check whether the unknown frame is valid, if not, the frame will be discarded, otherwise, the frame will be passed toSpdyFrameDecoder.decodeUnknownFrame(int, byte, int, ByteBuf).By default this method always returns
false, sub-classes may override this.
-
readFrameError
public void readFrameError(String message)
Description copied from interface:SpdyFrameDecoderDelegateCalled when an unrecoverable session error has occurred.- Specified by:
readFrameErrorin interfaceSpdyFrameDecoderDelegate
-
-