public interface HttpServer extends Measured
You receive HTTP requests by providing a requestHandler(io.vertx.core.Handler<io.vertx.core.http.HttpServerRequest>)
. As requests arrive on the server the handler
will be called with the requests.
You receive WebSockets by providing a webSocketHandler(io.vertx.core.Handler<io.vertx.core.http.ServerWebSocket>)
. As WebSocket connections arrive on the server, the
WebSocket is passed to the handler.
Modifier and Type | Method and Description |
---|---|
int |
actualPort()
The actual port the server is listening on.
|
Future<Void> |
close()
Close the server.
|
void |
close(Handler<AsyncResult<Void>> completionHandler)
Like
close() but supplying a handler that will be called when the server is actually closed (or has failed). |
HttpServer |
connectionHandler(Handler<HttpConnection> handler)
Set a connection handler for the server.
|
HttpServer |
exceptionHandler(Handler<Throwable> handler)
Set an exception handler called for socket errors happening before the HTTP connection
is established, e.g during the TLS handshake.
|
HttpServer |
invalidRequestHandler(Handler<HttpServerRequest> handler)
Set a
handler for handling invalid requests. |
Future<HttpServer> |
listen()
Tell the server to start listening.
|
default HttpServer |
listen(Handler<AsyncResult<HttpServer>> listenHandler)
Like
listen() but supplying a handler that will be called when the server is actually listening (or has failed). |
default Future<HttpServer> |
listen(int port)
Like
listen(int, String) but the server will listen on host "0.0.0.0" and port specified here ignoring
any value in the HttpServerOptions that was used when creating the server. |
default HttpServer |
listen(int port,
Handler<AsyncResult<HttpServer>> listenHandler)
Like
listen(int) but supplying a handler that will be called when the server is actually listening (or has failed). |
default Future<HttpServer> |
listen(int port,
String host)
Tell the server to start listening.
|
default HttpServer |
listen(int port,
String host,
Handler<AsyncResult<HttpServer>> listenHandler)
Like
listen(int, String) but supplying a handler that will be called when the server is actually
listening (or has failed). |
Future<HttpServer> |
listen(SocketAddress address)
Like
listen(SocketAddress, Handler) but returns a Future of the asynchronous result |
default HttpServer |
listen(SocketAddress address,
Handler<AsyncResult<HttpServer>> listenHandler)
Tell the server to start listening on the given address supplying
a handler that will be called when the server is actually
listening (or has failed).
|
Handler<HttpServerRequest> |
requestHandler() |
HttpServer |
requestHandler(Handler<HttpServerRequest> handler)
Set the request handler for the server to
requestHandler . |
ReadStream<HttpServerRequest> |
requestStream()
Deprecated.
instead use
requestHandler(Handler) |
default Future<Boolean> |
updateSSLOptions(SSLOptions options)
Update the server with new SSL
options , the update happens if the options object is valid and different
from the existing options object. |
Future<Boolean> |
updateSSLOptions(SSLOptions options,
boolean force)
Update the server with new SSL
options , the update happens if the options object is valid and different
from the existing options object. |
default void |
updateSSLOptions(SSLOptions options,
boolean force,
Handler<AsyncResult<Boolean>> handler)
Like
updateSSLOptions(SSLOptions) but supplying a handler that will be called when the update
happened (or has failed). |
default void |
updateSSLOptions(SSLOptions options,
Handler<AsyncResult<Boolean>> handler)
Like
updateSSLOptions(SSLOptions) but supplying a handler that will be called when the update
happened (or has failed). |
void |
updateTrafficShapingOptions(TrafficShapingOptions options)
Update traffic shaping options
options , the update happens if valid values are passed for traffic
shaping options. |
Handler<ServerWebSocket> |
webSocketHandler() |
HttpServer |
webSocketHandler(Handler<ServerWebSocket> handler)
Set the WebSocket handler for the server to
wsHandler . |
HttpServer |
webSocketHandshakeHandler(Handler<ServerWebSocketHandshake> handler)
Set a handler for WebSocket handshake.
|
ReadStream<ServerWebSocket> |
webSocketStream()
Deprecated.
instead use
webSocketHandler(Handler) |
isMetricsEnabled
@Deprecated ReadStream<HttpServerRequest> requestStream()
requestHandler(Handler)
HttpServerRequest
will be created and passed to the stream ReadStream.handler(io.vertx.core.Handler)
.HttpServer requestHandler(Handler<HttpServerRequest> handler)
requestHandler
. As HTTP requests are received by the server,
instances of HttpServerRequest
will be created and passed to this handler.Handler<HttpServerRequest> requestHandler()
HttpServer invalidRequestHandler(Handler<HttpServerRequest> handler)
handler
for handling invalid requests. When an invalid request is received by the server
this handler will be called with the request. The handler can send any HTTP response, when the response
ends, the server shall close the connection. HttpServerRequest.decoderResult()
can be used
to obtain the Netty decoder result and the failure cause reported by the decoder.
Currently this handler is only used for HTTP/1.x requests.
When no specific handler is set, the HttpServerRequest.DEFAULT_INVALID_REQUEST_HANDLER
is used.
HttpServer connectionHandler(Handler<HttpConnection> handler)
HttpServer exceptionHandler(Handler<Throwable> handler)
handler
- the handler to set@Deprecated ReadStream<ServerWebSocket> webSocketStream()
webSocketHandler(Handler)
ServerWebSocket
instance will be created and passed to the stream ReadStream.handler(io.vertx.core.Handler)
.HttpServer webSocketHandler(Handler<ServerWebSocket> handler)
wsHandler
. If a WebSocket connect handshake is successful a
new ServerWebSocket
instance will be created and passed to the handler.HttpServer webSocketHandshakeHandler(Handler<ServerWebSocketHandshake> handler)
When an inbound HTTP request presents a WebSocket upgrade, this handler is called first. The handler
can chose to ServerWebSocketHandshake.accept()
or ServerWebSocketHandshake.reject()
the request.
Setting no handler, implicitly accepts any HTTP request connection presenting an upgrade header and upgrades it to a WebSocket.
Handler<ServerWebSocket> webSocketHandler()
default Future<Boolean> updateSSLOptions(SSLOptions options)
options
, the update happens if the options object is valid and different
from the existing options object.
The boolean succeeded future result indicates whether the update occurred.
options
- the new SSL optionsdefault void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Boolean>> handler)
updateSSLOptions(SSLOptions)
but supplying a handler that will be called when the update
happened (or has failed).options
- the new SSL optionshandler
- the update handlerFuture<Boolean> updateSSLOptions(SSLOptions options, boolean force)
Update the server with new SSL options
, the update happens if the options object is valid and different
from the existing options object.
The options
object is compared using its equals
method against the existing options to prevent
an update when the objects are equals since loading options can be costly, this can happen for share TCP servers.
When object are equals, setting force
to true
forces the update.
The boolean succeeded future result indicates whether the update occurred.
options
- the new SSL optionsforce
- force the update when options are equalsdefault void updateSSLOptions(SSLOptions options, boolean force, Handler<AsyncResult<Boolean>> handler)
updateSSLOptions(SSLOptions)
but supplying a handler that will be called when the update
happened (or has failed).options
- the new SSL optionsforce
- force the update when options are equalshandler
- the update handlervoid updateTrafficShapingOptions(TrafficShapingOptions options)
options
, the update happens if valid values are passed for traffic
shaping options. This update happens synchronously and at best effort for rate update to take effect immediately.options
- the new traffic shaping optionsFuture<HttpServer> listen()
HttpServerOptions
that was used when creating the server.
The listen happens asynchronously and the server may not be listening until some time after the call has returned.
default Future<HttpServer> listen(int port, String host)
HttpServerOptions
that was used when creating the server.
The listen happens asynchronously and the server may not be listening until some time after the call has returned.
port
- the port to listen onhost
- the host to listen ondefault HttpServer listen(int port, String host, Handler<AsyncResult<HttpServer>> listenHandler)
listen(int, String)
but supplying a handler that will be called when the server is actually
listening (or has failed).port
- the port to listen onhost
- the host to listen onlistenHandler
- the listen handlerdefault HttpServer listen(SocketAddress address, Handler<AsyncResult<HttpServer>> listenHandler)
address
- the address to listen onlistenHandler
- the listen handlerFuture<HttpServer> listen(SocketAddress address)
listen(SocketAddress, Handler)
but returns a Future
of the asynchronous resultdefault Future<HttpServer> listen(int port)
listen(int, String)
but the server will listen on host "0.0.0.0" and port specified here ignoring
any value in the HttpServerOptions
that was used when creating the server.port
- the port to listen ondefault HttpServer listen(int port, Handler<AsyncResult<HttpServer>> listenHandler)
listen(int)
but supplying a handler that will be called when the server is actually listening (or has failed).port
- the port to listen onlistenHandler
- the listen handlerdefault HttpServer listen(Handler<AsyncResult<HttpServer>> listenHandler)
listen()
but supplying a handler that will be called when the server is actually listening (or has failed).listenHandler
- the listen handlerFuture<Void> close()
The close happens asynchronously and the server may not be closed until some time after the call has returned.
void close(Handler<AsyncResult<Void>> completionHandler)
close()
but supplying a handler that will be called when the server is actually closed (or has failed).completionHandler
- the handlerint actualPort()
Copyright © 2024 Eclipse. All rights reserved.