io.undertow.server.protocol.http2

## 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`

### Field Summary

### Fields inherited from interface org.xnio.channels.Configurable

`EMPTY`

### Constructor Summary

Constructors
Constructor and Description
`Http2ServerConnection(Http2Channel channel, Http2DataStreamSinkChannel sinkChannel, org.xnio.OptionMap undertowOptions, int bufferSize, HttpHandler rootHandler)` Channel that is used when the request is already half closed
`Http2ServerConnection(Http2Channel channel, Http2StreamSourceChannel requestChannel, org.xnio.OptionMap undertowOptions, int bufferSize, HttpHandler rootHandler)`

### Method Summary

All Methods Instance Methods Concrete Methods
`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> A` `getLocalAddress(Class<A> type)`
`<T> T` `getOption(org.xnio.Option<T> option)`
`SocketAddress` `getPeerAddress()` Returns the actual address of the remote connection.
`<A extends SocketAddress> A` `getPeerAddress(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`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### 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 class `ServerConnection`
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 auth `ServerConnection.getSslSessionInfo()` should be used instead, as it takes into account other information potentially provided by load balancers that terminate SSL

Overrides:
  `getSslSession` in class `ServerConnection`
Returns:
  The SSLSession of the connection

#### getByteBufferPool

    public ByteBufferPool getByteBufferPool()

Specified by:
  `getByteBufferPool` in class `ServerConnection`
Returns:
  The connections buffer pool

#### getWorker

    public org.xnio.XnioWorker getWorker()

Specified by:
  `getWorker` in interface `org.xnio.channels.CloseableChannel`
Specified by:
  `getWorker` in class `ServerConnection`
Returns:
  The connections worker

#### getIoThread

    public org.xnio.XnioIoThread getIoThread()

Specified by:
  `getIoThread` in interface `org.xnio.channels.CloseableChannel`
Specified by:
  `getIoThread` in class `ServerConnection`
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 class `ServerConnection`
Parameters:
  `exchange` - The current exchange
Returns:
  The out of band exchange.

#### isContinueResponseSupported

    public boolean isContinueResponseSupported()

Specified by:
  `isContinueResponseSupported` in class `ServerConnection`
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 class `ServerConnection`
Parameters:
  `exchange` - The current exchange.

#### isOpen

    public boolean isOpen()

Specified by:
  `isOpen` in interface `Channel`
Specified by:
  `isOpen` in class `ServerConnection`
Returns:
  true if the connection is open

#### supportsOption

    public boolean supportsOption(org.xnio.Option<?> option)

Specified by:
  `supportsOption` in interface `org.xnio.channels.Configurable`
Specified by:
  `supportsOption` in class `ServerConnection`

#### getOption

    public <T> T getOption(org.xnio.Option<T> option)
                    throws IOException

Specified by:
  `getOption` in interface `org.xnio.channels.Configurable`
Specified by:
  `getOption` in class `ServerConnection`
Throws:
  `IOException`

#### setOption

    public <T> T setOption(org.xnio.Option<T> option,
                           T value)
                    throws IllegalArgumentException,
                           IOException

Specified by:
  `setOption` in interface `org.xnio.channels.Configurable`
Specified by:
  `setOption` in class `ServerConnection`
Throws:
  `IllegalArgumentException`
  `IOException`

#### close

    public void close()
               throws IOException

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Channel`
Specified by:
  `close` in interface `InterruptibleChannel`
Specified by:
  `close` in interface `org.xnio.channels.CloseableChannel`
Specified by:
  `close` in class `ServerConnection`
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 interface `org.xnio.channels.ConnectedChannel`
Specified by:
  `getPeerAddress` in class `ServerConnection`
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 interface `org.xnio.channels.ConnectedChannel`
Specified by:
  `getPeerAddress` in class `ServerConnection`
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 interface `org.xnio.channels.BoundChannel`
Specified by:
  `getLocalAddress` in class `ServerConnection`

#### getLocalAddress

    public <A extends SocketAddress> A getLocalAddress(Class<A> type)

Specified by:
  `getLocalAddress` in interface `org.xnio.channels.BoundChannel`
Specified by:
  `getLocalAddress` in class `ServerConnection`

#### getUndertowOptions

    public org.xnio.OptionMap getUndertowOptions()

Specified by:
  `getUndertowOptions` in class `ServerConnection`

#### getBufferSize

    public int getBufferSize()

Specified by:
  `getBufferSize` in class `ServerConnection`

#### 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 class `ServerConnection`
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 class `ServerConnection`
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 class `ServerConnection`
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 class `ServerConnection`
Returns:
  The StreamConnection that should be passed to the upgrade handler

#### getSinkChannel

    protected org.xnio.conduits.ConduitStreamSinkChannel getSinkChannel()

Specified by:
  `getSinkChannel` in class `ServerConnection`

#### getSourceChannel

    protected org.xnio.conduits.ConduitStreamSourceChannel getSourceChannel()

Specified by:
  `getSourceChannel` in class `ServerConnection`

#### 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 class `ServerConnection`
Returns:
  The source conduit

#### isUpgradeSupported

    protected boolean isUpgradeSupported()

Specified by:
  `isUpgradeSupported` in class `ServerConnection`
Returns:
  true if this connection supports HTTP upgrade

#### isConnectSupported

    protected boolean isConnectSupported()

Specified by:
  `isConnectSupported` in class `ServerConnection`
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 class `ServerConnection`

#### setUpgradeListener

    protected void setUpgradeListener(HttpUpgradeListener upgradeListener)

Specified by:
  `setUpgradeListener` in class `ServerConnection`

#### setConnectListener

    protected void setConnectListener(HttpUpgradeListener connectListener)

Specified by:
  `setConnectListener` in class `ServerConnection`

#### 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 class `ServerConnection`
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 interface `Attachable`
Overrides:
  `addToAttachmentList` in class `AbstractAttachable`
Type Parameters:
  `T` - the list value type
Parameters:
  `key` - the attachment key
  `value` - 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 interface `Attachable`
Overrides:
  `removeAttachment` in class `AbstractAttachable`
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 is `null`, the attachment key is removed.

Specified by:
  `putAttachment` in interface `Attachable`
Overrides:
  `putAttachment` in class `AbstractAttachable`
Type Parameters:
  `T` - the value type
Parameters:
  `key` - the attachment key
  `value` - 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 interface `Attachable`
Overrides:
  `getAttachmentList` in class `AbstractAttachable`
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 interface `Attachable`
Overrides:
  `getAttachment` in class `AbstractAttachable`
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 class `ServerConnection`

#### isRequestTrailerFieldsSupported

    public boolean isRequestTrailerFieldsSupported()

Specified by:
  `isRequestTrailerFieldsSupported` in class `ServerConnection`

#### 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 class `ServerConnection`
Parameters:
  `path` - The path of the resource
  `method` - The request method
  `requestHeaders` - 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. The `HttpHandler` passed in will be used to generate the pushed response

Overrides:
  `pushResource` in class `ServerConnection`
Parameters:
  `path` - The path of the resource
  `method` - The request method
  `requestHeaders` - 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 class `ServerConnection`
Returns:
  the transport protocol