Package io.vertx.reactivex.core.http

## Class HttpServer

- java.lang.Object
- - io.vertx.reactivex.core.http.HttpServer

- All Implemented Interfaces:
    `Measured`

      public class HttpServer
      extends Object
      implements Measured

  An HTTP and WebSockets server.

  You receive HTTP requests by providing a `requestHandler(io.vertx.core.Handler<io.vertx.reactivex.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.reactivex.core.http.ServerWebSocket>)`. As WebSocket connections arrive on the server, the WebSocket is passed to the handler.

  NOTE: This class has been automatically generated from the `original` non RX-ified interface using Vert.x codegen.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static io.vertx.lang.rx.TypeArg<HttpServer>` | `__TYPE_ARG` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `HttpServer​(HttpServer delegate)` |
    `HttpServer​(Object delegate)` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `actualPort()` | The actual port the server is listening on.
    `Future<Void>` | `close()` | Close the server.
    `HttpServer` | `connectionHandler​(Handler<HttpConnection> handler)` | Set a connection handler for the server.
    `boolean` | `equals​(Object o)` |
    `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` | `getDelegate()` |
    `int` | `hashCode()` |
    `HttpServer` | `invalidRequestHandler​(Handler<HttpServerRequest> handler)` | Set a `handler` for handling invalid requests.
    `boolean` | `isMetricsEnabled()` | Whether the metrics are enabled for this measured object
    `Future<HttpServer>` | `listen()` | Tell the server to start listening.
    `Future<HttpServer>` | `listen​(int port)` | Like `listen()` 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.
    `Future<HttpServer>` | `listen​(int port, String host)` | Tell the server to start listening.
    `Future<HttpServer>` | `listen​(SocketAddress address)` | 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).
    `static HttpServer` | `newInstance​(HttpServer arg)` |
    `HttpServer` | `requestHandler​(Handler<HttpServerRequest> handler)` | Set the request handler for the server to `requestHandler`.
    `Completable` | `rxClose()` | Close the server.
    `Single<HttpServer>` | `rxListen()` | Tell the server to start listening.
    `Single<HttpServer>` | `rxListen​(int port)` | Like `listen()` 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.
    `Single<HttpServer>` | `rxListen​(int port, String host)` | Tell the server to start listening.
    `Single<HttpServer>` | `rxListen​(SocketAddress address)` | 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).
    `Completable` | `rxShutdown()` | Shutdown with a 30 seconds timeout (`shutdown(30, TimeUnit.SECONDS)`).
    `Completable` | `rxShutdown​(long timeout, TimeUnit unit)` | Initiate the server shutdown sequence.
    `Single<Boolean>` | `rxUpdateSSLOptions​(ServerSSLOptions options)` | Update the server with new SSL `options`, the update happens if the options object is valid and different from the existing options object.
    `Single<Boolean>` | `rxUpdateSSLOptions​(ServerSSLOptions 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.
    `Future<Void>` | `shutdown()` | Shutdown with a 30 seconds timeout (`shutdown(30, TimeUnit.SECONDS)`).
    `Future<Void>` | `shutdown​(long timeout, TimeUnit unit)` | Initiate the server shutdown sequence.
    `String` | `toString()` |
    `Future<Boolean>` | `updateSSLOptions​(ServerSSLOptions 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​(ServerSSLOptions 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.
    `void` | `updateTrafficShapingOptions​(TrafficShapingOptions options)` | Update traffic shaping options `options`, the update happens if valid values are passed for traffic shaping options.
    `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.

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

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### __TYPE_ARG

          public static final io.vertx.lang.rx.TypeArg<HttpServer> __TYPE_ARG

  - ### Constructor Detail

    - #### HttpServer

          public HttpServer​(HttpServer delegate)

    - #### HttpServer

          public HttpServer​(Object delegate)

  - ### Method Detail

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### equals

          public boolean equals​(Object o)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### getDelegate

          public HttpServer getDelegate()

      Specified by:
        `getDelegate` in interface `Measured`

    - #### isMetricsEnabled

          public boolean isMetricsEnabled()

      Whether the metrics are enabled for this measured object
      Specified by:
        `isMetricsEnabled` in interface `Measured`
      Returns:
        `true` if metrics are enabled

    - #### requestHandler

          public HttpServer requestHandler​(Handler<HttpServerRequest> handler)

      Set the request handler for the server to `requestHandler`. As HTTP requests are received by the server, instances of `HttpServerRequest` will be created and passed to this handler.
      Parameters:
        `handler` -
      Returns:
        a reference to this, so the API can be used fluently

    - #### invalidRequestHandler

          public HttpServer invalidRequestHandler​(Handler<HttpServerRequest> handler)

      Set a `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. `io.vertx.reactivex.core.http.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` is used.

      Parameters:
        `handler` -
      Returns:
        a reference to this, so the API can be used fluently

    - #### connectionHandler

          public HttpServer connectionHandler​(Handler<HttpConnection> handler)

      Set a connection handler for the server.
      The handler will always be called on the event-loop thread.
      Parameters:
        `handler` -
      Returns:
        a reference to this, so the API can be used fluently

    - #### webSocketHandshakeHandler

          public HttpServer webSocketHandshakeHandler​(Handler<ServerWebSocketHandshake> handler)

      Set a handler for WebSocket handshake.

      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.

      Parameters:
        `handler` -
      Returns:

    - #### exceptionHandler

          public 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.
      Parameters:
        `handler` - the handler to set
      Returns:
        a reference to this, so the API can be used fluently

    - #### webSocketHandler

          public HttpServer webSocketHandler​(Handler<ServerWebSocket> handler)

      Set the WebSocket handler for the server to `wsHandler`. If a WebSocket connect handshake is successful a new `ServerWebSocket` instance will be created and passed to the handler.
      Parameters:
        `handler` -
      Returns:
        a reference to this, so the API can be used fluently

    - #### updateSSLOptions

          public Future<Boolean> updateSSLOptions​(ServerSSLOptions options)

      Update the server with new SSL `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.

      Parameters:
        `options` - the new SSL options
      Returns:
        a future signaling the update success

    - #### rxUpdateSSLOptions

          public Single<Boolean> rxUpdateSSLOptions​(ServerSSLOptions options)

      Update the server with new SSL `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.

      Parameters:
        `options` - the new SSL options
      Returns:
        a future signaling the update success

    - #### updateSSLOptions

          public Future<Boolean> updateSSLOptions​(ServerSSLOptions 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.

      Parameters:
        `options` - the new SSL options
        `force` - force the update when options are equals
      Returns:
        a future signaling the update success

    - #### rxUpdateSSLOptions

          public Single<Boolean> rxUpdateSSLOptions​(ServerSSLOptions 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.

      Parameters:
        `options` - the new SSL options
        `force` - force the update when options are equals
      Returns:
        a future signaling the update success

    - #### updateTrafficShapingOptions

          public void updateTrafficShapingOptions​(TrafficShapingOptions options)

      Update traffic shaping 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.
      Parameters:
        `options` - the new traffic shaping options

    - #### listen

          public Future<HttpServer> listen()

      Tell the server to start listening. The server will listen on the port and host specified in the `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.

      Returns:
        a future completed with the listen operation result

    - #### rxListen

          public Single<HttpServer> rxListen()

      Tell the server to start listening. The server will listen on the port and host specified in the `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.

      Returns:
        a future completed with the listen operation result

    - #### listen

          public Future<HttpServer> listen​(int port,
                                           String host)

      Tell the server to start listening. The server will listen on the port and host specified here, ignoring any value set in the `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.

      Parameters:
        `port` - the port to listen on
        `host` - the host to listen on
      Returns:
        a future completed with the listen operation result

    - #### rxListen

          public Single<HttpServer> rxListen​(int port,
                                             String host)

      Tell the server to start listening. The server will listen on the port and host specified here, ignoring any value set in the `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.

      Parameters:
        `port` - the port to listen on
        `host` - the host to listen on
      Returns:
        a future completed with the listen operation result

    - #### listen

          public Future<HttpServer> listen​(SocketAddress address)

      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).
      Parameters:
        `address` - the address to listen on
      Returns:
        a future completed with the listen operation result

    - #### rxListen

          public Single<HttpServer> rxListen​(SocketAddress address)

      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).
      Parameters:
        `address` - the address to listen on
      Returns:
        a future completed with the listen operation result

    - #### listen

          public Future<HttpServer> listen​(int port)

      Like `listen()` 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.
      Parameters:
        `port` - the port to listen on
      Returns:
        a future completed with the listen operation result

    - #### rxListen

          public Single<HttpServer> rxListen​(int port)

      Like `listen()` 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.
      Parameters:
        `port` - the port to listen on
      Returns:
        a future completed with the listen operation result

    - #### close

          public Future<Void> close()

      Close the server. Any open HTTP connections will be closed.

      The close happens asynchronously and the server may not be closed until some time after the call has returned.

      Returns:
        a future completed with the result

    - #### rxClose

          public Completable rxClose()

      Close the server. Any open HTTP connections will be closed.

      The close happens asynchronously and the server may not be closed until some time after the call has returned.

      Returns:
        a future completed with the result

    - #### shutdown

          public Future<Void> shutdown()

      Shutdown with a 30 seconds timeout (`shutdown(30, TimeUnit.SECONDS)`).
      Returns:
        a future completed when shutdown has completed

    - #### rxShutdown

          public Completable rxShutdown()

      Shutdown with a 30 seconds timeout (`shutdown(30, TimeUnit.SECONDS)`).
      Returns:
        a future completed when shutdown has completed

    - #### shutdown

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

      Initiate the server shutdown sequence.

      Connections are taken out of service and closed when all inflight requests are processed. When all connections are closed the server is closed. When the `timeout` expires, all unclosed connections are immediately closed.

      - HTTP/2 connections will send a go away frame immediately to signal the other side the connection will close
      - HTTP/1.x server connection will be closed after the current response is sent
      Parameters:
        `timeout` - the amount of time after which all resources are forcibly closed
        `unit` - the of the timeout
      Returns:
        a future notified when the client is closed

    - #### rxShutdown

          public Completable rxShutdown​(long timeout,
                                        TimeUnit unit)

      Initiate the server shutdown sequence.

      Connections are taken out of service and closed when all inflight requests are processed. When all connections are closed the server is closed. When the `timeout` expires, all unclosed connections are immediately closed.

      - HTTP/2 connections will send a go away frame immediately to signal the other side the connection will close
      - HTTP/1.x server connection will be closed after the current response is sent
      Parameters:
        `timeout` - the amount of time after which all resources are forcibly closed
        `unit` - the of the timeout
      Returns:
        a future notified when the client is closed

    - #### actualPort

          public int actualPort()

      The actual port the server is listening on. This is useful if you bound the server specifying 0 as port number signifying an ephemeral port
      Returns:
        the actual port the server is listening on.

    - #### newInstance

          public static HttpServer newInstance​(HttpServer arg)