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 HttpStringAUTHORITYstatic java.lang.StringCLEARTEXT_UPGRADE_STRINGstatic intDEFAULT_INITIAL_WINDOW_SIZEstatic intDEFAULT_MAX_FRAME_SIZEstatic intERROR_CANCELstatic intERROR_COMPRESSION_ERRORstatic intERROR_CONNECT_ERRORstatic intERROR_ENHANCE_YOUR_CALMstatic intERROR_FLOW_CONTROL_ERRORstatic intERROR_FRAME_SIZE_ERRORstatic intERROR_INADEQUATE_SECURITYstatic intERROR_INTERNAL_ERRORstatic intERROR_NO_ERRORstatic intERROR_PROTOCOL_ERRORstatic intERROR_REFUSED_STREAMstatic intERROR_SETTINGS_TIMEOUTstatic intERROR_STREAM_CLOSEDstatic intFLOW_CONTROL_MIN_WINDOWstatic java.lang.StringHTTP2_MAX_HEADER_SIZE_PROPERTYName of the system property for configuring HTTP2 max header size:"io.undertow.http2-max-header-size".static intMAX_FRAME_SIZEstatic HttpStringMETHODstatic HttpStringPATHstatic HttpStringSCHEMEstatic HttpStringSTATUS
-
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 booleanaddPushPromiseStream(int pushedStreamId)Adds a received pushed stream into the current streams for a client.<T> voidaddToAttachmentList(AttachmentKey<AttachmentList<T>> key, T value)Add a value to a list-typed attachment key.protected voidcloseSubChannels()Method that is called when the channel is being forcibly closed, and all sub stream sink/source channels should also be forcibly closed.protected AbstractHttp2StreamSourceChannelcreateChannel(FrameHeaderData frameHeaderData, PooledByteBuffer frameData)Method that creates the actual stream source channel implementation that is in use.protected AbstractHttp2StreamSourceChannelcreateChannelImpl(FrameHeaderData frameHeaderData, PooledByteBuffer frameData)Http2HeadersStreamSinkChannelcreateInitialUpgradeResponseStream()Creates a response stream to respond to the initial HTTP upgradeHttp2HeadersStreamSinkChannelcreateStream(HeaderMap requestHeaders)Creates a strema using a HEADERS frame<T> TgetAttachment(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.intgetHttp2Version()intgetInitialReceiveWindowSize()intgetInitialSendWindowSize()java.lang.StringgetProtocol()java.lang.StringgetProtocolRequestId()intgetReceiveMaxConcurrentStreams()intgetReceiveMaxFrameSize()protected java.util.Collection<AbstractFramedStreamSourceChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>>getReceivers()intgetSendMaxConcurrentStreams()intgetSendMaxFrameSize()javax.net.ssl.SSLSessiongetSslSession()protected voidhandleBrokenSinkChannel(java.lang.Throwable e)Method that is invoked when then write side of a channel is broken.protected voidhandleBrokenSourceChannel(java.lang.Throwable e)Method that is invoked when the read side of the channel is broken.voidhandleWindowUpdate(int streamId, int deltaWindowSize)booleanisClient()protected booleanisLastFrameReceived()Returns true if the protocol specific final frame has been received.protected booleanisLastFrameSent()booleanisPeerGoneAway()booleanisPushEnabled()booleanisThisGoneAway()protected voidlastDataRead()Method than is invoked when read() returns -1.protected FrameHeaderDataparseFrame(java.nio.ByteBuffer data)Attempts to parse an incoming frame header from the data in the buffer.<T> TputAttachment(AttachmentKey<T> key, T value)Set an attachment value.<T> TremoveAttachment(AttachmentKey<T> key)Remove an attachment, returning its previous value.voidsendGoAway(int status)voidsendGoAway(int status, org.xnio.ChannelExceptionHandler<AbstractHttp2StreamSinkChannel> exceptionHandler)voidsendPing(byte[] data)voidsendPing(byte[] data, org.xnio.ChannelExceptionHandler<AbstractHttp2StreamSinkChannel> exceptionHandler)Http2HeadersStreamSinkChannelsendPushPromise(int associatedStreamId, HeaderMap requestHeaders, HeaderMap responseHeaders)voidsendRstStream(int streamId, int statusCode)voidsendUpdateWindowSize(int streamId, int delta)voidsetSendMaxConcurrentStreams(int sendMaxConcurrentStreams)voidupdateReceiveFlowControlWindow(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
-
HTTP2_MAX_HEADER_SIZE_PROPERTY
public static final java.lang.String HTTP2_MAX_HEADER_SIZE_PROPERTY
Name of the system property for configuring HTTP2 max header size:"io.undertow.http2-max-header-size".This system property will be replaced by an
Undertow option.- See Also:
- Constant Field Values
-
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:AbstractFramedChannelMethod that creates the actual stream source channel implementation that is in use.- Specified by:
createChannelin 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:AbstractFramedChannelAttempts to parse an incoming frame header from the data in the buffer.- Specified by:
parseFramein classAbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>- Parameters:
data- The data that has been read from the channel- Returns:
- The frame header data, or
nullif the data was incomplete - Throws:
java.io.IOException- If the data could not be parsed.
-
lastDataRead
protected void lastDataRead()
Description copied from class:AbstractFramedChannelMethod than is invoked when read() returns -1.- Overrides:
lastDataReadin classAbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>
-
isLastFrameReceived
protected boolean isLastFrameReceived()
Description copied from class:AbstractFramedChannelReturns true if the protocol specific final frame has been received.- Specified by:
isLastFrameReceivedin classAbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>- Returns:
trueIf the last frame has been received
-
isLastFrameSent
protected boolean isLastFrameSent()
- Specified by:
isLastFrameSentin classAbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>- Returns:
trueIf the last frame has been sent
-
handleBrokenSourceChannel
protected void handleBrokenSourceChannel(java.lang.Throwable e)
Description copied from class:AbstractFramedChannelMethod that is invoked when the read side of the channel is broken. This generally happens on a protocol error.- Specified by:
handleBrokenSourceChannelin classAbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>
-
handleBrokenSinkChannel
protected void handleBrokenSinkChannel(java.lang.Throwable e)
Description copied from class:AbstractFramedChannelMethod that is invoked when then write side of a channel is broken. This generally happens on a protocol error.- Specified by:
handleBrokenSinkChannelin classAbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>
-
closeSubChannels
protected void closeSubChannels()
Description copied from class:AbstractFramedChannelMethod that is called when the channel is being forcibly closed, and all sub stream sink/source channels should also be forcibly closed.- Specified by:
closeSubChannelsin classAbstractFramedChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>
-
getReceivers
protected java.util.Collection<AbstractFramedStreamSourceChannel<Http2Channel,AbstractHttp2StreamSourceChannel,AbstractHttp2StreamSinkChannel>> getReceivers()
- Specified by:
getReceiversin 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
-
getProtocolRequestId
public java.lang.String getProtocolRequestId()
-
addPushPromiseStream
public boolean addPushPromiseStream(int pushedStreamId) throws java.io.IOExceptionAdds 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:AttachableGet an attachment value. If no attachment exists for this key,nullis returned.- Specified by:
getAttachmentin interfaceAttachable- Type Parameters:
T- the value type- Parameters:
key- the attachment key- Returns:
- the value, or
nullif there is none
-
getAttachmentList
public <T> java.util.List<T> getAttachmentList(AttachmentKey<? extends java.util.List<T>> key)
Description copied from interface:AttachableGets a list attachment value. If not attachment exists for this key an empty list is returned- Specified by:
getAttachmentListin 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:AttachableSet 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:
putAttachmentin interfaceAttachable- Type Parameters:
T- the value type- Parameters:
key- the attachment keyvalue- the new value- Returns:
- the old value, or
nullif there was none
-
removeAttachment
public <T> T removeAttachment(AttachmentKey<T> key)
Description copied from interface:AttachableRemove an attachment, returning its previous value.- Specified by:
removeAttachmentin interfaceAttachable- Type Parameters:
T- the value type- Parameters:
key- the attachment key- Returns:
- the old value, or
nullif there was none
-
addToAttachmentList
public <T> void addToAttachmentList(AttachmentKey<AttachmentList<T>> key, T value)
Description copied from interface:AttachableAdd a value to a list-typed attachment key. If the key is not mapped, add such a mapping.- Specified by:
addToAttachmentListin 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()
-
-