Class Http2ServerConnection
- java.lang.Object
-
- io.undertow.util.AbstractAttachable
-
- io.undertow.server.ServerConnection
-
- io.undertow.server.protocol.http2.Http2ServerConnection
-
- 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 Http2ServerConnection extends ServerConnection
A server connection. There is one connection per request TODO: how are we going to deal with attachments?- Author:
- Stuart Douglas
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.undertow.server.ServerConnection
ServerConnection.CloseListener
-
-
Constructor Summary
Constructors Constructor Description Http2ServerConnection(Http2Channel channel, Http2DataStreamSinkChannel sinkChannel, org.xnio.OptionMap undertowOptions, int bufferSize, HttpHandler rootHandler)
Channel that is used when the request is already half closedHttp2ServerConnection(Http2Channel channel, Http2StreamSourceChannel requestChannel, org.xnio.OptionMap undertowOptions, int bufferSize, HttpHandler rootHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCloseListener(ServerConnection.CloseListener listener)
Adds a close listener, than will be invoked with the connection is closed<T> void
addToAttachmentList(AttachmentKey<AttachmentList<T>> key, T value)
Add a value to a list-typed attachment key.void
close()
protected void
exchangeComplete(HttpServerExchange exchange)
Invoked when the exchange is complete.<T> T
getAttachment(AttachmentKey<T> key)
Get an attachment value.<T> List<T>
getAttachmentList(AttachmentKey<? extends List<T>> key)
Gets a list attachment value.org.xnio.Pool<ByteBuffer>
getBufferPool()
int
getBufferSize()
ByteBufferPool
getByteBufferPool()
org.xnio.ChannelListener.Setter<? extends org.xnio.channels.ConnectedChannel>
getCloseSetter()
org.xnio.XnioIoThread
getIoThread()
SocketAddress
getLocalAddress()
<A extends SocketAddress>
AgetLocalAddress(Class<A> type)
<T> T
getOption(org.xnio.Option<T> option)
SocketAddress
getPeerAddress()
Returns the actual address of the remote connection.<A extends SocketAddress>
AgetPeerAddress(Class<A> type)
Returns the actual address of the remote connection.protected org.xnio.conduits.ConduitStreamSinkChannel
getSinkChannel()
protected org.xnio.conduits.StreamSinkConduit
getSinkConduit(HttpServerExchange exchange, org.xnio.conduits.StreamSinkConduit conduit)
Gets the sink conduit that should be used for this request.protected org.xnio.conduits.ConduitStreamSourceChannel
getSourceChannel()
SSLSession
getSslSession()
Gets the SSLSession of the underlying connection, or null if SSL is not in use.SSLSessionInfo
getSslSessionInfo()
Gets SSL information about the connection.String
getTransportProtocol()
Returns a string representation describing the protocol used to transmit messages on this connection.org.xnio.OptionMap
getUndertowOptions()
org.xnio.XnioWorker
getWorker()
protected boolean
isConnectSupported()
boolean
isContinueResponseSupported()
boolean
isOpen()
boolean
isPushSupported()
boolean
isRequestTrailerFieldsSupported()
protected boolean
isUpgradeSupported()
protected void
maxEntitySizeUpdated(HttpServerExchange exchange)
Callback that is invoked if the max entity size is updated.boolean
pushResource(String path, HttpString method, HeaderMap requestHeaders)
Attempts to push a resource if this connection supports server push.boolean
pushResource(String path, HttpString method, HeaderMap requestHeaders, HttpHandler handler)
Attempts to push a resource if this connection supports server push.<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.HttpServerExchange
sendOutOfBandResponse(HttpServerExchange exchange)
Sends an out of band response, such as a HTTP 100-continue response.protected void
setConnectListener(HttpUpgradeListener connectListener)
<T> T
setOption(org.xnio.Option<T> option, T value)
void
setSslSessionInfo(SSLSessionInfo sessionInfo)
Sets the current SSL information.protected void
setUpgradeListener(HttpUpgradeListener upgradeListener)
boolean
supportsOption(org.xnio.Option<?> option)
void
terminateRequestChannel(HttpServerExchange exchange)
Invoked when the exchange is complete, and there is still data in the request channel.protected org.xnio.StreamConnection
upgradeChannel()
Upgrade the connection, if allowed-
Methods inherited from class io.undertow.util.AbstractAttachable
createAttachmentMap
-
-
-
-
Constructor Detail
-
Http2ServerConnection
public Http2ServerConnection(Http2Channel channel, Http2StreamSourceChannel requestChannel, org.xnio.OptionMap undertowOptions, int bufferSize, HttpHandler rootHandler)
-
Http2ServerConnection
public Http2ServerConnection(Http2Channel channel, Http2DataStreamSinkChannel sinkChannel, org.xnio.OptionMap undertowOptions, int bufferSize, HttpHandler rootHandler)
Channel that is used when the request is already half closed- Parameters:
channel
-undertowOptions
-bufferSize
-rootHandler
-
-
-
Method Detail
-
getBufferPool
public org.xnio.Pool<ByteBuffer> getBufferPool()
- Specified by:
getBufferPool
in classServerConnection
- Returns:
- The connections buffer pool
-
getSslSession
public SSLSession getSslSession()
Description copied from class:ServerConnection
Gets the SSLSession of the underlying connection, or null if SSL is not in use. Note that for client cert authServerConnection.getSslSessionInfo()
should be used instead, as it takes into account other information potentially provided by load balancers that terminate SSL- Overrides:
getSslSession
in classServerConnection
- Returns:
- The SSLSession of the connection
-
getByteBufferPool
public ByteBufferPool getByteBufferPool()
- Specified by:
getByteBufferPool
in classServerConnection
- Returns:
- The connections buffer pool
-
getWorker
public org.xnio.XnioWorker getWorker()
- Specified by:
getWorker
in interfaceorg.xnio.channels.CloseableChannel
- Specified by:
getWorker
in classServerConnection
- Returns:
- The connections worker
-
getIoThread
public org.xnio.XnioIoThread getIoThread()
- Specified by:
getIoThread
in interfaceorg.xnio.channels.CloseableChannel
- Specified by:
getIoThread
in classServerConnection
- Returns:
- The IO thread associated with the connection
-
sendOutOfBandResponse
public HttpServerExchange sendOutOfBandResponse(HttpServerExchange exchange)
Description copied from class:ServerConnection
Sends an out of band response, such as a HTTP 100-continue response. WARNING: do not attempt to write to the current exchange until the out of band exchange has been fully written. Doing so may have unexpected results. TODO: this needs more thought.- Specified by:
sendOutOfBandResponse
in classServerConnection
- Parameters:
exchange
- The current exchange- Returns:
- The out of band exchange.
-
isContinueResponseSupported
public boolean isContinueResponseSupported()
- Specified by:
isContinueResponseSupported
in classServerConnection
- Returns:
true
if this connection supports sending a 100-continue response
-
terminateRequestChannel
public void terminateRequestChannel(HttpServerExchange exchange)
Description copied from class:ServerConnection
Invoked when the exchange is complete, and there is still data in the request channel. Some implementations (such as SPDY and HTTP2) have more efficient ways to drain the request than simply reading all data (e.g. RST_STREAM). After this method is invoked the stream will be drained normally.- Specified by:
terminateRequestChannel
in classServerConnection
- Parameters:
exchange
- The current exchange.
-
isOpen
public boolean isOpen()
- Specified by:
isOpen
in interfaceChannel
- Specified by:
isOpen
in classServerConnection
- Returns:
- true if the connection is open
-
supportsOption
public boolean supportsOption(org.xnio.Option<?> option)
- Specified by:
supportsOption
in interfaceorg.xnio.channels.Configurable
- Specified by:
supportsOption
in classServerConnection
-
getOption
public <T> T getOption(org.xnio.Option<T> option) throws IOException
- Specified by:
getOption
in interfaceorg.xnio.channels.Configurable
- Specified by:
getOption
in classServerConnection
- Throws:
IOException
-
setOption
public <T> T setOption(org.xnio.Option<T> option, T value) throws IllegalArgumentException, IOException
- Specified by:
setOption
in interfaceorg.xnio.channels.Configurable
- Specified by:
setOption
in classServerConnection
- Throws:
IllegalArgumentException
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceorg.xnio.channels.CloseableChannel
- Specified by:
close
in interfaceInterruptibleChannel
- Specified by:
close
in classServerConnection
- Throws:
IOException
-
getPeerAddress
public SocketAddress getPeerAddress()
Description copied from class:ServerConnection
Returns the actual address of the remote connection. This will not take things like X-Forwarded-for into account.- Specified by:
getPeerAddress
in interfaceorg.xnio.channels.ConnectedChannel
- Specified by:
getPeerAddress
in classServerConnection
- Returns:
- The address of the remote peer
-
getPeerAddress
public <A extends SocketAddress> A getPeerAddress(Class<A> type)
Description copied from class:ServerConnection
Returns the actual address of the remote connection. This will not take things like X-Forwarded-for into account.- Specified by:
getPeerAddress
in interfaceorg.xnio.channels.ConnectedChannel
- Specified by:
getPeerAddress
in classServerConnection
- Type Parameters:
A
- The address type- Parameters:
type
- The type of address to return- Returns:
- The remote endpoint address
-
getCloseSetter
public org.xnio.ChannelListener.Setter<? extends org.xnio.channels.ConnectedChannel> getCloseSetter()
-
getLocalAddress
public SocketAddress getLocalAddress()
- Specified by:
getLocalAddress
in interfaceorg.xnio.channels.BoundChannel
- Specified by:
getLocalAddress
in classServerConnection
-
getLocalAddress
public <A extends SocketAddress> A getLocalAddress(Class<A> type)
- Specified by:
getLocalAddress
in interfaceorg.xnio.channels.BoundChannel
- Specified by:
getLocalAddress
in classServerConnection
-
getUndertowOptions
public org.xnio.OptionMap getUndertowOptions()
- Specified by:
getUndertowOptions
in classServerConnection
-
getBufferSize
public int getBufferSize()
- Specified by:
getBufferSize
in classServerConnection
-
getSslSessionInfo
public SSLSessionInfo getSslSessionInfo()
Description copied from class:ServerConnection
Gets SSL information about the connection. This could represent the actual client connection, or could be providing SSL information that was provided by a front end proxy.- Specified by:
getSslSessionInfo
in classServerConnection
- Returns:
- SSL information about the connection
-
setSslSessionInfo
public void setSslSessionInfo(SSLSessionInfo sessionInfo)
Description copied from class:ServerConnection
Sets the current SSL information. This can be used by handlers to setup SSL information that was provided by a front end proxy. If this is being set of a per request basis then you must ensure that it is either cleared by an exchange completion listener at the end of the request, or is always set for every request. Otherwise it is possible to SSL information to 'leak' between requests.- Specified by:
setSslSessionInfo
in classServerConnection
- Parameters:
sessionInfo
- The ssl session information
-
addCloseListener
public void addCloseListener(ServerConnection.CloseListener listener)
Description copied from class:ServerConnection
Adds a close listener, than will be invoked with the connection is closed- Specified by:
addCloseListener
in classServerConnection
- Parameters:
listener
- The close listener
-
upgradeChannel
protected org.xnio.StreamConnection upgradeChannel()
Description copied from class:ServerConnection
Upgrade the connection, if allowed- Specified by:
upgradeChannel
in classServerConnection
- Returns:
- The StreamConnection that should be passed to the upgrade handler
-
getSinkChannel
protected org.xnio.conduits.ConduitStreamSinkChannel getSinkChannel()
- Specified by:
getSinkChannel
in classServerConnection
-
getSourceChannel
protected org.xnio.conduits.ConduitStreamSourceChannel getSourceChannel()
- Specified by:
getSourceChannel
in classServerConnection
-
getSinkConduit
protected org.xnio.conduits.StreamSinkConduit getSinkConduit(HttpServerExchange exchange, org.xnio.conduits.StreamSinkConduit conduit)
Description copied from class:ServerConnection
Gets the sink conduit that should be used for this request. This allows the connection to apply any per-request conduit wrapping that is required, without adding to the response wrappers array. There is no corresponding method for source conduits, as in general conduits can be directly inserted into the connection after the request has been read.- Specified by:
getSinkConduit
in classServerConnection
- Returns:
- The source conduit
-
isUpgradeSupported
protected boolean isUpgradeSupported()
- Specified by:
isUpgradeSupported
in classServerConnection
- Returns:
- true if this connection supports HTTP upgrade
-
isConnectSupported
protected boolean isConnectSupported()
- Specified by:
isConnectSupported
in classServerConnection
- Returns:
true
if this connection supports the HTTP CONNECT verb
-
exchangeComplete
protected void exchangeComplete(HttpServerExchange exchange)
Description copied from class:ServerConnection
Invoked when the exchange is complete.- Specified by:
exchangeComplete
in classServerConnection
-
setUpgradeListener
protected void setUpgradeListener(HttpUpgradeListener upgradeListener)
- Specified by:
setUpgradeListener
in classServerConnection
-
setConnectListener
protected void setConnectListener(HttpUpgradeListener connectListener)
- Specified by:
setConnectListener
in classServerConnection
-
maxEntitySizeUpdated
protected void maxEntitySizeUpdated(HttpServerExchange exchange)
Description copied from class:ServerConnection
Callback that is invoked if the max entity size is updated.- Specified by:
maxEntitySizeUpdated
in classServerConnection
- Parameters:
exchange
- The current exchange
-
addToAttachmentList
public <T> void addToAttachmentList(AttachmentKey<AttachmentList<T>> key, T value)
Description copied from class:AbstractAttachable
Add a value to a list-typed attachment key. If the key is not mapped, add such a mapping.- Specified by:
addToAttachmentList
in interfaceAttachable
- Overrides:
addToAttachmentList
in classAbstractAttachable
- Type Parameters:
T
- the list value type- Parameters:
key
- the attachment keyvalue
- the value to add
-
removeAttachment
public <T> T removeAttachment(AttachmentKey<T> key)
Description copied from class:AbstractAttachable
Remove an attachment, returning its previous value.- Specified by:
removeAttachment
in interfaceAttachable
- Overrides:
removeAttachment
in classAbstractAttachable
- Type Parameters:
T
- the value type- Parameters:
key
- the attachment key- Returns:
- the old value, or
null
if there was none
-
putAttachment
public <T> T putAttachment(AttachmentKey<T> key, T value)
Description copied from class:AbstractAttachable
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
- Overrides:
putAttachment
in classAbstractAttachable
- Type Parameters:
T
- the value type- Parameters:
key
- the attachment keyvalue
- the new value- Returns:
- the old value, or
null
if there was none
-
getAttachmentList
public <T> List<T> getAttachmentList(AttachmentKey<? extends List<T>> key)
Description copied from class:AbstractAttachable
Gets a list attachment value. If not attachment exists for this key an empty list is returned- Specified by:
getAttachmentList
in interfaceAttachable
- Overrides:
getAttachmentList
in classAbstractAttachable
- Type Parameters:
T
- the value type- Parameters:
key
- the attachment key- Returns:
- the value, or an empty list if there is none
-
getAttachment
public <T> T getAttachment(AttachmentKey<T> key)
Description copied from class:AbstractAttachable
Get an attachment value. If no attachment exists for this key,null
is returned.- Specified by:
getAttachment
in interfaceAttachable
- Overrides:
getAttachment
in classAbstractAttachable
- Type Parameters:
T
- the value type- Parameters:
key
- the attachment key- Returns:
- the value, or
null
if there is none
-
isPushSupported
public boolean isPushSupported()
- Overrides:
isPushSupported
in classServerConnection
-
isRequestTrailerFieldsSupported
public boolean isRequestTrailerFieldsSupported()
- Specified by:
isRequestTrailerFieldsSupported
in classServerConnection
-
pushResource
public boolean pushResource(String path, HttpString method, HeaderMap requestHeaders)
Description copied from class:ServerConnection
Attempts to push a resource if this connection supports server push. Otherwise the request is ignored. Note that push is always done on a best effort basis, even if this method returns true it is possible that the remote endpoint will reset the stream- Overrides:
pushResource
in classServerConnection
- Parameters:
path
- The path of the resourcemethod
- The request methodrequestHeaders
- The request headers- Returns:
true
if the server attempted the push, false otherwise
-
pushResource
public boolean pushResource(String path, HttpString method, HeaderMap requestHeaders, HttpHandler handler)
Description copied from class:ServerConnection
Attempts to push a resource if this connection supports server push. Otherwise the request is ignored. Note that push is always done on a best effort basis, even if this method returns true it is possible that the remote endpoint will reset the stream. TheHttpHandler
passed in will be used to generate the pushed response- Overrides:
pushResource
in classServerConnection
- Parameters:
path
- The path of the resourcemethod
- The request methodrequestHeaders
- The request headers- Returns:
true
if the server attempted the push, false otherwise
-
getTransportProtocol
public String getTransportProtocol()
Description copied from class:ServerConnection
Returns a string representation describing the protocol used to transmit messages on this connection.- Specified by:
getTransportProtocol
in classServerConnection
- Returns:
- the transport protocol
-
-