An HTTP and WebSockets server.

You receive HTTP requests by providing a requestHandler. As requests arrive on the server the handler will be called with the requests.

You receive WebSockets by providing a websocketHandler. As WebSocket connections arrive on the server, the WebSocket is passed to the handler.

no subtypes hierarchy

Initializer
HttpServer(HttpServer unknown)
Inherited Attributes
Attributes inherited from: Object
hash, string
Methods
actualPortshared default Integer 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

closeshared default 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.

closeshared default void close(Anything(Throwable?) completionHandler)

Like close but supplying a handler that will be called when the server is actually closed (or has failed).

Parameters:
  • completionHandler

    the handler

connectionHandlershared default HttpServer connectionHandler(Anything(HttpConnection) handler)

Set a connection handler for the server.

exceptionHandlershared default HttpServer exceptionHandler(Anything(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

isMetricsEnabledshared actual default Boolean isMetricsEnabled()

Whether the metrics are enabled for this measured object

listenshared default 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.

listenshared default HttpServer listen(Anything(Throwable|HttpServer) listenHandler)

Like listen but supplying a handler that will be called when the server is actually listening (or has failed).

Parameters:
  • listenHandler

    the listen handler

listenshared default HttpServer listen(Integer 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

listenshared default HttpServer listen(Integer port, Anything(Throwable|HttpServer) listenHandler)

Like listen but supplying a handler that will be called when the server is actually listening (or has failed).

Parameters:
  • port

    the port to listen on

  • listenHandler

    the listen handler

listenshared default HttpServer listen(Integer 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

listenshared default HttpServer listen(Integer port, String host, Anything(Throwable|HttpServer) listenHandler)

Like listen but supplying a handler that will be called when the server is actually listening (or has failed).

Parameters:
  • port

    the port to listen on

  • host

    the host to listen on

  • listenHandler

    the listen handler

requestHandlershared default HttpServer requestHandler(Anything(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.

requestStreamshared default ReadStream<HttpServerRequest> requestStream()

Return the request stream for the server. As HTTP requests are received by the server, instances of HttpServerRequest will be created and passed to the stream .

websocketHandlershared default HttpServer websocketHandler(Anything(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.

websocketStreamshared default ReadStream<ServerWebSocket> websocketStream()

Return the websocket stream for the server. If a websocket connect handshake is successful a new ServerWebSocket instance will be created and passed to the stream .

Inherited Methods
Methods inherited from: Object
equals
Methods inherited from: Measured