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
,Closeable
,AutoCloseable
,Channel
,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
FieldsModifier and TypeFieldDescriptionstatic final HttpString
static final String
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final HttpString
static final HttpString
static final HttpString
static final HttpString
Fields inherited from interface org.xnio.channels.Configurable
EMPTY
-
Constructor Summary
ConstructorsConstructorDescriptionHttp2Channel
(org.xnio.StreamConnection connectedStreamChannel, String protocol, ByteBufferPool bufferPool, PooledByteBuffer data, boolean clientSide, boolean fromUpgrade, boolean prefaceRequired, ByteBuffer initialOtherSideSettings, org.xnio.OptionMap settings) Http2Channel
(org.xnio.StreamConnection connectedStreamChannel, String protocol, ByteBufferPool bufferPool, PooledByteBuffer data, boolean clientSide, boolean fromUpgrade, boolean prefaceRequired, org.xnio.OptionMap settings) Http2Channel
(org.xnio.StreamConnection connectedStreamChannel, String protocol, ByteBufferPool bufferPool, PooledByteBuffer data, boolean clientSide, boolean fromUpgrade, org.xnio.OptionMap settings) -
Method Summary
Modifier and TypeMethodDescriptionboolean
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
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) Creates a response stream to respond to the initial HTTP upgradecreateStream
(HeaderMap requestHeaders) Creates a strema using a HEADERS frame<T> T
getAttachment
(AttachmentKey<T> key) Get an attachment value.<T> List<T>
getAttachmentList
(AttachmentKey<? extends List<T>> key) Gets a list attachment value.int
int
int
int
int
protected Collection<AbstractFramedStreamSourceChannel<Http2Channel,
AbstractHttp2StreamSourceChannel, AbstractHttp2StreamSinkChannel>> int
int
protected void
Method that is invoked when then write side of a channel is broken.protected void
Method that is invoked when the read side of the channel is broken.void
handleWindowUpdate
(int streamId, int deltaWindowSize) boolean
isClient()
protected boolean
Returns true if the protocol specific final frame has been received.protected boolean
boolean
boolean
boolean
protected void
Method than is invoked when read() returns -1.protected FrameHeaderData
parseFrame
(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) 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 Details
-
CLEARTEXT_UPGRADE_STRING
- See Also:
-
METHOD
-
PATH
-
SCHEME
-
AUTHORITY
-
STATUS
-
ERROR_NO_ERROR
public static final int ERROR_NO_ERROR- See Also:
-
ERROR_PROTOCOL_ERROR
public static final int ERROR_PROTOCOL_ERROR- See Also:
-
ERROR_INTERNAL_ERROR
public static final int ERROR_INTERNAL_ERROR- See Also:
-
ERROR_FLOW_CONTROL_ERROR
public static final int ERROR_FLOW_CONTROL_ERROR- See Also:
-
ERROR_SETTINGS_TIMEOUT
public static final int ERROR_SETTINGS_TIMEOUT- See Also:
-
ERROR_STREAM_CLOSED
public static final int ERROR_STREAM_CLOSED- See Also:
-
ERROR_FRAME_SIZE_ERROR
public static final int ERROR_FRAME_SIZE_ERROR- See Also:
-
ERROR_REFUSED_STREAM
public static final int ERROR_REFUSED_STREAM- See Also:
-
ERROR_CANCEL
public static final int ERROR_CANCEL- See Also:
-
ERROR_COMPRESSION_ERROR
public static final int ERROR_COMPRESSION_ERROR- See Also:
-
ERROR_CONNECT_ERROR
public static final int ERROR_CONNECT_ERROR- See Also:
-
ERROR_ENHANCE_YOUR_CALM
public static final int ERROR_ENHANCE_YOUR_CALM- See Also:
-
ERROR_INADEQUATE_SECURITY
public static final int ERROR_INADEQUATE_SECURITY- See Also:
-
DEFAULT_INITIAL_WINDOW_SIZE
public static final int DEFAULT_INITIAL_WINDOW_SIZE- See Also:
-
DEFAULT_MAX_FRAME_SIZE
public static final int DEFAULT_MAX_FRAME_SIZE- See Also:
-
MAX_FRAME_SIZE
public static final int MAX_FRAME_SIZE- See Also:
-
FLOW_CONTROL_MIN_WINDOW
public static final int FLOW_CONTROL_MIN_WINDOW- See Also:
-
-
Constructor Details
-
Http2Channel
public Http2Channel(org.xnio.StreamConnection connectedStreamChannel, String protocol, ByteBufferPool bufferPool, PooledByteBuffer data, boolean clientSide, boolean fromUpgrade, org.xnio.OptionMap settings) -
Http2Channel
public Http2Channel(org.xnio.StreamConnection connectedStreamChannel, String protocol, ByteBufferPool bufferPool, PooledByteBuffer data, boolean clientSide, boolean fromUpgrade, boolean prefaceRequired, org.xnio.OptionMap settings) -
Http2Channel
public Http2Channel(org.xnio.StreamConnection connectedStreamChannel, String protocol, ByteBufferPool bufferPool, PooledByteBuffer data, boolean clientSide, boolean fromUpgrade, boolean prefaceRequired, ByteBuffer initialOtherSideSettings, org.xnio.OptionMap settings)
-
-
Method Details
-
createChannel
protected AbstractHttp2StreamSourceChannel createChannel(FrameHeaderData frameHeaderData, PooledByteBuffer frameData) throws 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:
IOException
-
createChannelImpl
protected AbstractHttp2StreamSourceChannel createChannelImpl(FrameHeaderData frameHeaderData, PooledByteBuffer frameData) throws IOException - Throws:
IOException
-
parseFrame
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:
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. -
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
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. -
handleBrokenSinkChannel
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. -
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 Collection<AbstractFramedStreamSourceChannel<Http2Channel,AbstractHttp2StreamSourceChannel, getReceivers()AbstractHttp2StreamSinkChannel>> - 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
- Throws:
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
- Throws:
IOException
-
getSslSession
-
updateReceiveFlowControlWindow
- Throws:
IOException
-
createStream
Creates a strema using a HEADERS frame- Parameters:
requestHeaders
-- Returns:
- Throws:
IOException
-
addPushPromiseStream
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:
IOException
- General error like not being a client or odd stream id
-
sendPushPromise
public Http2HeadersStreamSinkChannel sendPushPromise(int associatedStreamId, HeaderMap requestHeaders, HeaderMap responseHeaders) throws IOException - Throws:
IOException
-
isClient
public boolean isClient() -
getAttachment
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
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
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
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
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
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
-