Top Description Methods
io.vertx.core.http

public Interface HttpConnection

Known Direct Subinterfaces
io.vertx.core.http.impl.HttpServerConnection, io.vertx.core.http.impl.HttpClientConnection
Known Direct Implementers
io.vertx.core.http.impl.Http1xConnectionBase, io.vertx.core.http.impl.Http2ConnectionBase
Annotations
@VertxGen
Imports
io.vertx.codegen.annotations.*, io.vertx.core.AsyncResult, .Future, .Handler, io.vertx.core.buffer.Buffer, io.vertx.core.net.SocketAddress, javax.net.ssl.SSLPeerUnverifiedException, .SSLSession, javax.security.cert.X509Certificate, java.security.cert.Certificate, java.util.List, java.util.concurrent.TimeUnit

Represents an HTTP connection.

HTTP/1.x connection provides an limited implementation, the following methods are implemented:

Author
Julien Viet

Method Summary

Modifier and TypeMethod and Description
public Future<Void>
close()

Like close(Handler) but returns a Future of the asynchronous result

public default void
close(Handler<AsyncResult<Void>>
the handler to be completed when the connection is closed
handler
)

Close the connection and all the currently active streams.

public HttpConnection

Returns:

a reference to this, so the API can be used fluently
closeHandler
(Handler<Void>
the handler to be notified
handler
)

Set a close handler.

public HttpConnection

Returns:

a reference to this, so the API can be used fluently
exceptionHandler
(Handler<Throwable>
the handler
handler
)

Set an handler called when a connection error happens

public default int

Returns:

the current connection window size or -1 for HTTP/1.x
getWindowSize
()

public default HttpConnection
goAway(long errorCode)

Like goAway(long, int) with a last stream id -1 which means to disallow any new stream creation.

public default HttpConnection
goAway(long errorCode, int lastStreamId)

Like goAway(long, int, Buffer) with no buffer.

public HttpConnection

Returns:

a reference to this, so the API can be used fluently
goAway
(long
the GOAWAY error code
errorCode
,
int
the last stream id
lastStreamId
,
Buffer
additional debug data sent to the remote endpoint
debugData
)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Send a go away frame to the remote endpoint of the connection.

public HttpConnection

Returns:

a reference to this, so the API can be used fluently
goAwayHandler
(@Nullable Handler<GoAway>
the handler
handler
)

Set an handler called when a GOAWAY frame is received.

public String

Returns:

the indicated server name
indicatedServerName
()

Returns the SNI server name presented during the SSL handshake by the client.

public boolean

Returns:

true if this io.vertx.core.http.HttpConnection is encrypted via SSL/TLS.
isSsl
()

public SocketAddress

Returns:

the local address for this connection, possibly null (e.g a server bound on a domain socket) If useProxyProtocol is set to true, the address returned will be of the proxy.
localAddress
()

public SocketAddress
localAddress(boolean real)

Like localAddress() ()} but returns the server local address when real is true

public X509Certificate[]

Returns:

an ordered array of the peer certificates. Returns null if connection is not SSL.
peerCertificateChain
()
Deprecated instead use peerCertificates() or sslSession()

Note

Java SE 5+ recommends to use javax.net.ssl.SSLSession#getPeerCertificates() instead of of javax.net.ssl.SSLSession#getPeerCertificateChain() which this method is based on.

public List<Certificate>

Returns:

an ordered list of the peer certificates. Returns null if connection is not SSL.
peerCertificates
()

public HttpConnection

Returns:

a reference to this, so the API can be used fluently
ping
(Buffer
the 8 bytes data of the frame
data
,
Handler<AsyncResult<Buffer>>
an async result handler notified with pong reply or the failure
pongHandler
)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Send a PING frame to the remote endpoint.

public Future<Buffer>
ping(Buffer data)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Same as ping(Buffer, Handler) but returns a Future of the asynchronous result

public HttpConnection

Returns:

a reference to this, so the API can be used fluently
pingHandler
(@Nullable Handler<Buffer>
the handler to be called when a PING is received
handler
)

Set an handler notified when a PING frame is received from the remote endpoint.

public SocketAddress

Returns:

the remote address for this connection, possibly null (e.g a server bound on a domain socket). If useProxyProtocol is set to true, the address returned will be of the actual connecting client.
remoteAddress
()

public SocketAddress
remoteAddress(boolean real)

Like remoteAddress() but returns the proxy remote address when real is true

public Http2Settings

Returns:

the current remote endpoint settings for this connection - this is not implemented for HTTP/1.x
remoteSettings
()

public HttpConnection

Returns:

a reference to this, so the API can be used fluently
remoteSettingsHandler
(Handler<Http2Settings>
the handler for remote endpoint settings
handler
)

Set an handler that is called when remote endpoint Http2Settings are updated.

public Http2Settings

Returns:

the latest server settings acknowledged by the remote endpoint - this is not implemented for HTTP/1.x
settings
()

public default HttpConnection

Returns:

a reference to this, so the API can be used fluently
setWindowSize
(int
the new window size
windowSize
)

Update the current connection wide window size to a new size.

public default void
shutdown(Handler<AsyncResult<Void>> handler)

Shutdown a 30 seconds timeout (shutdown(30, TimeUnit.SECONDS)).

public default Future<Void>
shutdown()

Like shutdown(Handler) but returns a Future of the asynchronous result

public default void
shutdown(long timeout, Handler<AsyncResult<Void>> handler)
Deprecated instead use shutdown(long, TimeUnit, Handler)

Like shutdown(long, TimeUnit, Handler), in milliseconds.

public default Future<Void>
shutdown(long timeoutMs)
Deprecated instead use shutdown(long, TimeUnit)

Like shutdown(long, Handler) but returns a Future of the asynchronous result

public default void
shutdown(long
the amount of time after which all resources are forcibly closed
timeout
,
TimeUnit
the of the timeout
unit
,
Handler<AsyncResult<Void>>
the handler notified with the result
handler
)

Initiate a graceful connection shutdown, the connection is taken out of service and closed when all the inflight requests are processed, otherwise after a timeout the connection will be closed.

public Future<Void>
shutdown(long timeout, TimeUnit unit)

Like shutdown(long, TimeUnit, Handler) but returns a Future of the asynchronous result

public HttpConnection

Returns:

a reference to this, so the API can be used fluently
shutdownHandler
(@Nullable Handler<Void>
the handler
handler
)

Set an handler called when a GOAWAY frame has been sent or received and all connections are closed.

public SSLSession

Returns:

SSLSession associated with the underlying socket. Returns null if connection is not SSL.
sslSession
()

public Future<Void>

Returns:

a future completed with the result
updateSettings
(Http2Settings
the new settings
settings
)

Send to the remote endpoint an update of the server settings.

public HttpConnection

Returns:

a reference to this, so the API can be used fluently
updateSettings
(Http2Settings
the new settings
settings
,
Handler<AsyncResult<Void>>
the handler notified when the settings have been acknowledged by the remote endpoint
completionHandler
)

Send to the remote endpoint an update of this endpoint settings

The completionHandler will be notified when the remote endpoint has acknowledged the settings.

Method Detail

closeback to summary
public Future<Void> close()

Like close(Handler) but returns a Future of the asynchronous result

closeback to summary
public default void close(Handler<AsyncResult<Void>> handler)

Close the connection and all the currently active streams.

An HTTP/2 connection will send a GOAWAY frame before.

Parameters
handler:Handler<AsyncResult<Void>>

the handler to be completed when the connection is closed

closeHandlerback to summary
public HttpConnection closeHandler(Handler<Void> handler)

Set a close handler. The handler will get notified when the connection is closed.

Parameters
handler:Handler<Void>

the handler to be notified

Returns:HttpConnection

a reference to this, so the API can be used fluently

Annotations
@Fluent
exceptionHandlerback to summary
public HttpConnection exceptionHandler(Handler<Throwable> handler)

Set an handler called when a connection error happens

Parameters
handler:Handler<Throwable>

the handler

Returns:HttpConnection

a reference to this, so the API can be used fluently

Annotations
@Fluent
getWindowSizeback to summary
public default int getWindowSize()
Returns:int

the current connection window size or -1 for HTTP/1.x

goAwayback to summary
public default HttpConnection goAway(long errorCode)

Like goAway(long, int) with a last stream id -1 which means to disallow any new stream creation.

Annotations
@Fluent
goAwayback to summary
public default HttpConnection goAway(long errorCode, int lastStreamId)

Like goAway(long, int, Buffer) with no buffer.

Annotations
@Fluent
goAwayback to summary
public HttpConnection goAway(long errorCode, int lastStreamId, Buffer debugData)

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Send a go away frame to the remote endpoint of the connection.

  • a GOAWAY frame is sent to the to the remote endpoint with the errorCode and debugData
  • any stream created after the stream identified by lastStreamId will be closed
  • for an errorCode is different than 0 when all the remaining streams are closed this connection will be closed automatically

This is not implemented for HTTP/1.x.

Parameters
errorCode:long

the GOAWAY error code

lastStreamId:int

the last stream id

debugData:Buffer

additional debug data sent to the remote endpoint

Returns:HttpConnection

a reference to this, so the API can be used fluently

Annotations
@Fluent
goAwayHandlerback to summary
public HttpConnection goAwayHandler(@Nullable Handler<GoAway> handler)

Set an handler called when a GOAWAY frame is received.

This is not implemented for HTTP/1.x.

Parameters
handler:@Nullable Handler<GoAway>

the handler

Returns:HttpConnection

a reference to this, so the API can be used fluently

Annotations
@Fluent
indicatedServerNameback to summary
public String indicatedServerName()

Returns the SNI server name presented during the SSL handshake by the client.

Returns:String

the indicated server name

isSslback to summary
public boolean isSsl()
Returns:boolean

true if this io.vertx.core.http.HttpConnection is encrypted via SSL/TLS.

localAddressback to summary
public SocketAddress localAddress()
Returns:SocketAddress

the local address for this connection, possibly null (e.g a server bound on a domain socket) If useProxyProtocol is set to true, the address returned will be of the proxy.

Annotations
@CacheReturn
localAddressback to summary
public SocketAddress localAddress(boolean real)

Like localAddress() ()} but returns the server local address when real is true

peerCertificateChainback to summary
public X509Certificate[] peerCertificateChain() throws SSLPeerUnverifiedException

Deprecated

instead use peerCertificates() or sslSession()

Note

Java SE 5+ recommends to use javax.net.ssl.SSLSession#getPeerCertificates() instead of of javax.net.ssl.SSLSession#getPeerCertificateChain() which this method is based on. Use sslSession() to access that method.

Returns:X509Certificate[]

an ordered array of the peer certificates. Returns null if connection is not SSL.

Annotations
@Deprecated
@GenIgnore
Exceptions
SSLPeerUnverifiedException:
SSL peer's identity has not been verified.
See Also
javax.net.ssl.SSLSession#getPeerCertificateChain(), sslSession()
peerCertificatesback to summary
public List<Certificate> peerCertificates() throws SSLPeerUnverifiedException
Returns:List<Certificate>

an ordered list of the peer certificates. Returns null if connection is not SSL.

Annotations
@GenIgnore
Exceptions
SSLPeerUnverifiedException:
SSL peer's identity has not been verified.
See Also
javax.net.ssl.SSLSession#getPeerCertificateChain(), sslSession()
pingback to summary
public HttpConnection ping(Buffer data, Handler<AsyncResult<Buffer>> pongHandler)

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Send a PING frame to the remote endpoint.

This is not implemented for HTTP/1.x.

Parameters
data:Buffer

the 8 bytes data of the frame

pongHandler:Handler<AsyncResult<Buffer>>

an async result handler notified with pong reply or the failure

Returns:HttpConnection

a reference to this, so the API can be used fluently

Annotations
@Fluent
pingback to summary
public Future<Buffer> ping(Buffer data)

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Same as ping(Buffer, Handler) but returns a Future of the asynchronous result

pingHandlerback to summary
public HttpConnection pingHandler(@Nullable Handler<Buffer> handler)

Set an handler notified when a PING frame is received from the remote endpoint.

This is not implemented for HTTP/1.x.

Parameters
handler:@Nullable Handler<Buffer>

the handler to be called when a PING is received

Returns:HttpConnection

a reference to this, so the API can be used fluently

Annotations
@Fluent
remoteAddressback to summary
public SocketAddress remoteAddress()
Returns:SocketAddress

the remote address for this connection, possibly null (e.g a server bound on a domain socket). If useProxyProtocol is set to true, the address returned will be of the actual connecting client.

Annotations
@CacheReturn
remoteAddressback to summary
public SocketAddress remoteAddress(boolean real)

Like remoteAddress() but returns the proxy remote address when real is true

remoteSettingsback to summary
public Http2Settings remoteSettings()
Returns:Http2Settings

the current remote endpoint settings for this connection - this is not implemented for HTTP/1.x

remoteSettingsHandlerback to summary
public HttpConnection remoteSettingsHandler(Handler<Http2Settings> handler)

Set an handler that is called when remote endpoint Http2Settings are updated.

This is not implemented for HTTP/1.x.

Parameters
handler:Handler<Http2Settings>

the handler for remote endpoint settings

Returns:HttpConnection

a reference to this, so the API can be used fluently

Annotations
@Fluent
settingsback to summary
public Http2Settings settings()
Returns:Http2Settings

the latest server settings acknowledged by the remote endpoint - this is not implemented for HTTP/1.x

setWindowSizeback to summary
public default HttpConnection setWindowSize(int windowSize)

Update the current connection wide window size to a new size.

Increasing this value, gives better performance when several data streams are multiplexed

This is not implemented for HTTP/1.x.

Parameters
windowSize:int

the new window size

Returns:HttpConnection

a reference to this, so the API can be used fluently

Annotations
@Fluent
shutdownback to summary
public default void shutdown(Handler<AsyncResult<Void>> handler)

Shutdown a 30 seconds timeout (shutdown(30, TimeUnit.SECONDS)).

shutdownback to summary
public default Future<Void> shutdown()

Like shutdown(Handler) but returns a Future of the asynchronous result

shutdownback to summary
public default void shutdown(long timeout, Handler<AsyncResult<Void>> handler)

Deprecated

instead use shutdown(long, TimeUnit, Handler)

Like shutdown(long, TimeUnit, Handler), in milliseconds.

Annotations
@Deprecated
shutdownback to summary
public default Future<Void> shutdown(long timeoutMs)

Deprecated

instead use shutdown(long, TimeUnit)

Like shutdown(long, Handler) but returns a Future of the asynchronous result

Annotations
@Deprecated
shutdownback to summary
public default void shutdown(long timeout, TimeUnit unit, Handler<AsyncResult<Void>> handler)

Initiate a graceful connection shutdown, the connection is taken out of service and closed when all the inflight requests are processed, otherwise after a timeout the connection will be closed. Client connection are immediately removed from the pool.

  • HTTP/2 connections will send a go away frame immediately to signal the other side the connection will close.
  • HTTP/1.x connection will be closed.
Parameters
timeout:long

the amount of time after which all resources are forcibly closed

unit:TimeUnit

the of the timeout

handler:Handler<AsyncResult<Void>>

the handler notified with the result

shutdownback to summary
public Future<Void> shutdown(long timeout, TimeUnit unit)

Like shutdown(long, TimeUnit, Handler) but returns a Future of the asynchronous result

shutdownHandlerback to summary
public HttpConnection shutdownHandler(@Nullable Handler<Void> handler)

Set an handler called when a GOAWAY frame has been sent or received and all connections are closed.

This is not implemented for HTTP/1.x.

Parameters
handler:@Nullable Handler<Void>

the handler

Returns:HttpConnection

a reference to this, so the API can be used fluently

Annotations
@Fluent
sslSessionback to summary
public SSLSession sslSession()
Returns:SSLSession

SSLSession associated with the underlying socket. Returns null if connection is not SSL.

Annotations
@GenIgnore:permitted-type
See Also
javax.net.ssl.SSLSession
updateSettingsback to summary
public Future<Void> updateSettings(Http2Settings settings)

Send to the remote endpoint an update of the server settings.

This is not implemented for HTTP/1.x.

Parameters
settings:Http2Settings

the new settings

Returns:Future<Void>

a future completed with the result

updateSettingsback to summary
public HttpConnection updateSettings(Http2Settings settings, Handler<AsyncResult<Void>> completionHandler)

Send to the remote endpoint an update of this endpoint settings

The completionHandler will be notified when the remote endpoint has acknowledged the settings.

This is not implemented for HTTP/1.x.

Parameters
settings:Http2Settings

the new settings

completionHandler:Handler<AsyncResult<Void>>

the handler notified when the settings have been acknowledged by the remote endpoint

Returns:HttpConnection

a reference to this, so the API can be used fluently

Annotations
@Fluent