Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HttpServer

An HTTP and WebSockets server.

You receive HTTP requests by providing a {@link HttpServer#requestHandler}. As requests arrive on the server the handler will be called with the requests.

You receive WebSockets by providing a {@link HttpServer#webSocketHandler}. As WebSocket connections arrive on the server, the WebSocket is passed to the handler.

Hierarchy

  • HttpServer

Implements

Index

Methods

actualPort

  • actualPort(): number
  • 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 number

close

  • Like {@link HttpServer#close} but supplying a handler that will be called when the server is actually closed (or has failed).

    Returns PromiseLike<void>

  • Like {@link HttpServer#close} but supplying a handler that will be called when the server is actually closed (or has failed).

    Parameters

    Returns void

connectionHandler

  • Set a connection handler for the server.
    The handler will always be called on the event-loop thread.

    Parameters

    Returns HttpServer

exceptionHandler

  • Set an exception handler called for socket errors happening before the HTTP connection is established, e.g during the TLS handshake.

    Parameters

    Returns HttpServer

invalidRequestHandler

  • 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. {@link 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 DEFAULT_INVALID_REQUEST_HANDLER is used.

    Parameters

    Returns HttpServer

isMetricsEnabled

  • isMetricsEnabled(): boolean
  • Whether the metrics are enabled for this measured object

    Returns boolean

listen

  • Like {@link HttpServer#listen} but supplying a handler that will be called when the server is actually listening (or has failed).

    Parameters

    • port: number
    • host: string

    Returns PromiseLike<HttpServer>

  • Like {@link HttpServer#listen} but supplying a handler that will be called when the server is actually listening (or has failed).

    Parameters

    Returns HttpServer

  • 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

    Returns PromiseLike<HttpServer>

  • 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

    Returns HttpServer

  • Like {@link HttpServer#listen} but supplying a handler that will be called when the server is actually listening (or has failed).

    Parameters

    • port: number

    Returns PromiseLike<HttpServer>

  • Like {@link HttpServer#listen} but supplying a handler that will be called when the server is actually listening (or has failed).

    Parameters

    Returns HttpServer

  • Like {@link HttpServer#listen} but supplying a handler that will be called when the server is actually listening (or has failed).

    Returns PromiseLike<HttpServer>

  • Like {@link HttpServer#listen} but supplying a handler that will be called when the server is actually listening (or has failed).

    Parameters

    Returns HttpServer

requestHandler

  • 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

    Returns HttpServer

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 {@link ReadStream#handler}.

    Returns ReadStream<HttpServerRequest>

updateSSLOptions

  • Like {@link HttpServer#updateSSLOptions} but supplying a handler that will be called when the update happened (or has failed).

    Parameters

    Returns PromiseLike<void>

  • Like {@link HttpServer#updateSSLOptions} but supplying a handler that will be called when the update happened (or has failed).

    Parameters

    Returns void

webSocketHandler

  • 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

    Returns HttpServer

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 {@link ReadStream#handler}.

    Returns ReadStream<ServerWebSocket>

Generated using TypeDoc