Package io.undertow.protocols.http2
Class Http2Channel
- java.lang.Object
-
- io.undertow.server.protocol.framed.AbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>
-
- io.undertow.protocols.http2.Http2Channel
-
- All Implemented Interfaces:
Attachable
,java.io.Closeable
,java.lang.AutoCloseable
,java.nio.channels.Channel
,java.nio.channels.InterruptibleChannel
,org.xnio.channels.BoundChannel
,org.xnio.channels.CloseableChannel
,org.xnio.channels.Configurable
,org.xnio.channels.ConnectedChannel
public class Http2Channel extends AbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel> implements Attachable
HTTP2 channel.- Author:
- Stuart Douglas
-
-
Field Summary
Fields Modifier and Type Field Description static HttpString
AUTHORITY
static java.lang.String
CLEARTEXT_UPGRADE_STRING
static int
DEFAULT_INITIAL_WINDOW_SIZE
static int
DEFAULT_MAX_FRAME_SIZE
static int
ERROR_CANCEL
static int
ERROR_COMPRESSION_ERROR
static int
ERROR_CONNECT_ERROR
static int
ERROR_ENHANCE_YOUR_CALM
static int
ERROR_FLOW_CONTROL_ERROR
static int
ERROR_FRAME_SIZE_ERROR
static int
ERROR_INADEQUATE_SECURITY
static int
ERROR_INTERNAL_ERROR
static int
ERROR_NO_ERROR
static int
ERROR_PROTOCOL_ERROR
static int
ERROR_REFUSED_STREAM
static int
ERROR_SETTINGS_TIMEOUT
static int
ERROR_STREAM_CLOSED
static int
FLOW_CONTROL_MIN_WINDOW
static int
MAX_FRAME_SIZE
static HttpString
METHOD
static HttpString
PATH
static HttpString
SCHEME
static HttpString
STATUS
-
Constructor Summary
Constructors Constructor Description Http2Channel(org.xnio.StreamConnection connectedStreamChannel, java.lang.String protocol, ByteBufferPool bufferPool, PooledByteBuffer data, boolean clientSide, boolean fromUpgrade, boolean prefaceRequired, java.nio.ByteBuffer initialOtherSideSettings, org.xnio.OptionMap settings)
Http2Channel(org.xnio.StreamConnection connectedStreamChannel, java.lang.String protocol, ByteBufferPool bufferPool, PooledByteBuffer data, boolean clientSide, boolean fromUpgrade, boolean prefaceRequired, org.xnio.OptionMap settings)
Http2Channel(org.xnio.StreamConnection connectedStreamChannel, java.lang.String protocol, ByteBufferPool bufferPool, PooledByteBuffer data, boolean clientSide, boolean fromUpgrade, org.xnio.OptionMap settings)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addPushPromiseStream(int pushedStreamId)
Adds a received pushed stream into the current streams for a client.<T> void
addToAttachmentList(AttachmentKey<AttachmentList<T>> key, T value)
Add a value to a list-typed attachment key.protected void
closeSubChannels()
Method that is called when the channel is being forcibly closed, and all sub stream sink/source channels should also be forcibly closed.protected AbstractHttp2StreamSourceChannel
createChannel(FrameHeaderData frameHeaderData, PooledByteBuffer frameData)
Method that creates the actual stream source channel implementation that is in use.protected AbstractHttp2StreamSourceChannel
createChannelImpl(FrameHeaderData frameHeaderData, PooledByteBuffer frameData)
Http2HeadersStreamSinkChannel
createInitialUpgradeResponseStream()
Creates a response stream to respond to the initial HTTP upgradeHttp2HeadersStreamSinkChannel
createStream(HeaderMap requestHeaders)
Creates a strema using a HEADERS frame<T> T
getAttachment(AttachmentKey<T> key)
Get an attachment value.<T> java.util.List<T>
getAttachmentList(AttachmentKey<? extends java.util.List<T>> key)
Gets a list attachment value.int
getHttp2Version()
int
getInitialReceiveWindowSize()
int
getInitialSendWindowSize()
java.lang.String
getProtocol()
int
getReceiveMaxConcurrentStreams()
int
getReceiveMaxFrameSize()
protected java.util.Collection<AbstractFramedStreamSourceChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>>
getReceivers()
int
getSendMaxConcurrentStreams()
int
getSendMaxFrameSize()
javax.net.ssl.SSLSession
getSslSession()
protected void
handleBrokenSinkChannel(java.lang.Throwable e)
Method that is invoked when then write side of a channel is broken.protected void
handleBrokenSourceChannel(java.lang.Throwable e)
Method that is invoked when the read side of the channel is broken.void
handleWindowUpdate(int streamId, int deltaWindowSize)
boolean
isClient()
protected boolean
isLastFrameReceived()
Returns true if the protocol specific final frame has been received.protected boolean
isLastFrameSent()
boolean
isPeerGoneAway()
boolean
isPushEnabled()
boolean
isThisGoneAway()
protected void
lastDataRead()
Method than is invoked when read() returns -1.protected FrameHeaderData
parseFrame(java.nio.ByteBuffer data)
Attempts to parse an incoming frame header from the data in the buffer.<T> T
putAttachment(AttachmentKey<T> key, T value)
Set an attachment value.<T> T
removeAttachment(AttachmentKey<T> key)
Remove an attachment, returning its previous value.void
sendGoAway(int status)
void
sendGoAway(int status, org.xnio.ChannelExceptionHandler<AbstractHttp2StreamSinkChannel> exceptionHandler)
void
sendPing(byte[] data)
void
sendPing(byte[] data, org.xnio.ChannelExceptionHandler<AbstractHttp2StreamSinkChannel> exceptionHandler)
Http2HeadersStreamSinkChannel
sendPushPromise(int associatedStreamId, HeaderMap requestHeaders, HeaderMap responseHeaders)
void
sendRstStream(int streamId, int statusCode)
void
sendUpdateWindowSize(int streamId, int delta)
void
setSendMaxConcurrentStreams(int sendMaxConcurrentStreams)
void
updateReceiveFlowControlWindow(int read)
-
Methods inherited from class io.undertow.server.protocol.framed.AbstractFramedChannel
addCloseTask, close, createIdleTimeoutChannel, flush, flushSenders, getBufferPool, getCloseSetter, getDestinationAddress, getFramePriority, getIdleTimeout, getIoThread, getLocalAddress, getLocalAddress, getOption, getPeerAddress, getPeerAddress, getReceiveSetter, getSettings, getSourceAddress, getUnderlyingConnection, getWorker, isOpen, isReadsBroken, isReceivesResumed, isRequireExplicitFlush, isWritesBroken, markReadsBroken, markWritesBroken, queueFrame, recalculateHeldFrames, receive, resumeReceives, setIdleTimeout, setOption, setRequireExplicitFlush, supportsOption, suspendReceives, toString, writeExceptionHandler
-
-
-
-
Field Detail
-
CLEARTEXT_UPGRADE_STRING
public static final java.lang.String CLEARTEXT_UPGRADE_STRING
- See Also:
- Constant Field Values
-
METHOD
public static final HttpString METHOD
-
PATH
public static final HttpString PATH
-
SCHEME
public static final HttpString SCHEME
-
AUTHORITY
public static final HttpString AUTHORITY
-
STATUS
public static final HttpString STATUS
-
ERROR_NO_ERROR
public static final int ERROR_NO_ERROR
- See Also:
- Constant Field Values
-
ERROR_PROTOCOL_ERROR
public static final int ERROR_PROTOCOL_ERROR
- See Also:
- Constant Field Values
-
ERROR_INTERNAL_ERROR
public static final int ERROR_INTERNAL_ERROR
- See Also:
- Constant Field Values
-
ERROR_FLOW_CONTROL_ERROR
public static final int ERROR_FLOW_CONTROL_ERROR
- See Also:
- Constant Field Values
-
ERROR_SETTINGS_TIMEOUT
public static final int ERROR_SETTINGS_TIMEOUT
- See Also:
- Constant Field Values
-
ERROR_STREAM_CLOSED
public static final int ERROR_STREAM_CLOSED
- See Also:
- Constant Field Values
-
ERROR_FRAME_SIZE_ERROR
public static final int ERROR_FRAME_SIZE_ERROR
- See Also:
- Constant Field Values
-
ERROR_REFUSED_STREAM
public static final int ERROR_REFUSED_STREAM
- See Also:
- Constant Field Values
-
ERROR_CANCEL
public static final int ERROR_CANCEL
- See Also:
- Constant Field Values
-
ERROR_COMPRESSION_ERROR
public static final int ERROR_COMPRESSION_ERROR
- See Also:
- Constant Field Values
-
ERROR_CONNECT_ERROR
public static final int ERROR_CONNECT_ERROR
- See Also:
- Constant Field Values
-
ERROR_ENHANCE_YOUR_CALM
public static final int ERROR_ENHANCE_YOUR_CALM
- See Also:
- Constant Field Values
-
ERROR_INADEQUATE_SECURITY
public static final int ERROR_INADEQUATE_SECURITY
- See Also:
- Constant Field Values
-
DEFAULT_INITIAL_WINDOW_SIZE
public static final int DEFAULT_INITIAL_WINDOW_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_MAX_FRAME_SIZE
public static final int DEFAULT_MAX_FRAME_SIZE
- See Also:
- Constant Field Values
-
MAX_FRAME_SIZE
public static final int MAX_FRAME_SIZE
- See Also:
- Constant Field Values
-
FLOW_CONTROL_MIN_WINDOW
public static final int FLOW_CONTROL_MIN_WINDOW
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Http2Channel
public Http2Channel(org.xnio.StreamConnection connectedStreamChannel, java.lang.String protocol, ByteBufferPool bufferPool, PooledByteBuffer data, boolean clientSide, boolean fromUpgrade, org.xnio.OptionMap settings)
-
Http2Channel
public Http2Channel(org.xnio.StreamConnection connectedStreamChannel, java.lang.String protocol, ByteBufferPool bufferPool, PooledByteBuffer data, boolean clientSide, boolean fromUpgrade, boolean prefaceRequired, org.xnio.OptionMap settings)
-
Http2Channel
public Http2Channel(org.xnio.StreamConnection connectedStreamChannel, java.lang.String protocol, ByteBufferPool bufferPool, PooledByteBuffer data, boolean clientSide, boolean fromUpgrade, boolean prefaceRequired, java.nio.ByteBuffer initialOtherSideSettings, org.xnio.OptionMap settings)
-
-
Method Detail
-
createChannel
protected AbstractHttp2StreamSourceChannel createChannel(FrameHeaderData frameHeaderData, PooledByteBuffer frameData) throws java.io.IOException
Description copied from class:AbstractFramedChannel
Method that creates the actual stream source channel implementation that is in use.- Specified by:
createChannel
in classAbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>
- Parameters:
frameHeaderData
- The header data, as returned byAbstractFramedChannel.parseFrame(java.nio.ByteBuffer)
frameData
- Any additional data for the frame that has already been read. This may not be the complete frame contents- Returns:
- A new stream source channel
- Throws:
java.io.IOException
-
createChannelImpl
protected AbstractHttp2StreamSourceChannel createChannelImpl(FrameHeaderData frameHeaderData, PooledByteBuffer frameData) throws java.io.IOException
- Throws:
java.io.IOException
-
parseFrame
protected FrameHeaderData parseFrame(java.nio.ByteBuffer data) throws java.io.IOException
Description copied from class:AbstractFramedChannel
Attempts to parse an incoming frame header from the data in the buffer.- Specified by:
parseFrame
in classAbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>
- Parameters:
data
- The data that has been read from the channel- Returns:
- The frame header data, or
null
if the data was incomplete - Throws:
java.io.IOException
- If the data could not be parsed.
-
lastDataRead
protected void lastDataRead()
Description copied from class:AbstractFramedChannel
Method than is invoked when read() returns -1.- Overrides:
lastDataRead
in classAbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>
-
isLastFrameReceived
protected boolean isLastFrameReceived()
Description copied from class:AbstractFramedChannel
Returns true if the protocol specific final frame has been received.- Specified by:
isLastFrameReceived
in classAbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>
- Returns:
true
If the last frame has been received
-
isLastFrameSent
protected boolean isLastFrameSent()
- Specified by:
isLastFrameSent
in classAbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>
- Returns:
true
If the last frame has been sent
-
handleBrokenSourceChannel
protected void handleBrokenSourceChannel(java.lang.Throwable e)
Description copied from class:AbstractFramedChannel
Method that is invoked when the read side of the channel is broken. This generally happens on a protocol error.- Specified by:
handleBrokenSourceChannel
in classAbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>
-
handleBrokenSinkChannel
protected void handleBrokenSinkChannel(java.lang.Throwable e)
Description copied from class:AbstractFramedChannel
Method that is invoked when then write side of a channel is broken. This generally happens on a protocol error.- Specified by:
handleBrokenSinkChannel
in classAbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>
-
closeSubChannels
protected void closeSubChannels()
Description copied from class:AbstractFramedChannel
Method that is called when the channel is being forcibly closed, and all sub stream sink/source channels should also be forcibly closed.- Specified by:
closeSubChannels
in classAbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>
-
getReceivers
protected java.util.Collection<AbstractFramedStreamSourceChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>> getReceivers()
- Specified by:
getReceivers
in classAbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>
-
getHttp2Version
public int getHttp2Version()
-
getInitialSendWindowSize
public int getInitialSendWindowSize()
-
getInitialReceiveWindowSize
public int getInitialReceiveWindowSize()
-
getSendMaxConcurrentStreams
public int getSendMaxConcurrentStreams()
-
setSendMaxConcurrentStreams
public void setSendMaxConcurrentStreams(int sendMaxConcurrentStreams)
-
getReceiveMaxConcurrentStreams
public int getReceiveMaxConcurrentStreams()
-
handleWindowUpdate
public void handleWindowUpdate(int streamId, int deltaWindowSize) throws java.io.IOException
- Throws:
java.io.IOException
-
sendPing
public void sendPing(byte[] data)
-
sendPing
public void sendPing(byte[] data, org.xnio.ChannelExceptionHandler<AbstractHttp2StreamSinkChannel> exceptionHandler)
-
sendGoAway
public void sendGoAway(int status)
-
sendGoAway
public void sendGoAway(int status, org.xnio.ChannelExceptionHandler<AbstractHttp2StreamSinkChannel> exceptionHandler)
-
sendUpdateWindowSize
public void sendUpdateWindowSize(int streamId, int delta) throws java.io.IOException
- Throws:
java.io.IOException
-
getSslSession
public javax.net.ssl.SSLSession getSslSession()
-
updateReceiveFlowControlWindow
public void updateReceiveFlowControlWindow(int read) throws java.io.IOException
- Throws:
java.io.IOException
-
createStream
public Http2HeadersStreamSinkChannel createStream(HeaderMap requestHeaders) throws java.io.IOException
Creates a strema using a HEADERS frame- Parameters:
requestHeaders
-- Returns:
- Throws:
java.io.IOException
-
addPushPromiseStream
public boolean addPushPromiseStream(int pushedStreamId) throws java.io.IOException
Adds a received pushed stream into the current streams for a client. The stream is added into the currentStream and lastAssignedStreamOtherSide is incremented.- Parameters:
pushedStreamId
- The pushed stream returned by the server- Returns:
- true if pushedStreamId can be added, false if invalid
- Throws:
java.io.IOException
- General error like not being a client or odd stream id
-
sendPushPromise
public Http2HeadersStreamSinkChannel sendPushPromise(int associatedStreamId, HeaderMap requestHeaders, HeaderMap responseHeaders) throws java.io.IOException
- Throws:
java.io.IOException
-
isClient
public boolean isClient()
-
getAttachment
public <T> T getAttachment(AttachmentKey<T> key)
Description copied from interface:Attachable
Get an attachment value. If no attachment exists for this key,null
is returned.- Specified by:
getAttachment
in interfaceAttachable
- Type Parameters:
T
- the value type- Parameters:
key
- the attachment key- Returns:
- the value, or
null
if there is none
-
getAttachmentList
public <T> java.util.List<T> getAttachmentList(AttachmentKey<? extends java.util.List<T>> key)
Description copied from interface:Attachable
Gets a list attachment value. If not attachment exists for this key an empty list is returned- Specified by:
getAttachmentList
in interfaceAttachable
- Type Parameters:
T
- the value type- Parameters:
key
- the attachment key- Returns:
- the value, or an empty list if there is none
-
putAttachment
public <T> T putAttachment(AttachmentKey<T> key, T value)
Description copied from interface:Attachable
Set an attachment value. If an attachment for this key was already set, return the original value. If the value being set isnull
, the attachment key is removed.- Specified by:
putAttachment
in interfaceAttachable
- Type Parameters:
T
- the value type- Parameters:
key
- the attachment keyvalue
- the new value- Returns:
- the old value, or
null
if there was none
-
removeAttachment
public <T> T removeAttachment(AttachmentKey<T> key)
Description copied from interface:Attachable
Remove an attachment, returning its previous value.- Specified by:
removeAttachment
in interfaceAttachable
- Type Parameters:
T
- the value type- Parameters:
key
- the attachment key- Returns:
- the old value, or
null
if there was none
-
addToAttachmentList
public <T> void addToAttachmentList(AttachmentKey<AttachmentList<T>> key, T value)
Description copied from interface:Attachable
Add a value to a list-typed attachment key. If the key is not mapped, add such a mapping.- Specified by:
addToAttachmentList
in interfaceAttachable
- Type Parameters:
T
- the list value type- Parameters:
key
- the attachment keyvalue
- the value to add
-
sendRstStream
public void sendRstStream(int streamId, int statusCode)
-
createInitialUpgradeResponseStream
public Http2HeadersStreamSinkChannel createInitialUpgradeResponseStream()
Creates a response stream to respond to the initial HTTP upgrade- Returns:
-
isPushEnabled
public boolean isPushEnabled()
-
isPeerGoneAway
public boolean isPeerGoneAway()
-
isThisGoneAway
public boolean isThisGoneAway()
-
getReceiveMaxFrameSize
public int getReceiveMaxFrameSize()
-
getSendMaxFrameSize
public int getSendMaxFrameSize()
-
getProtocol
public java.lang.String getProtocol()
-
-