Class HttpServer

java.lang.Object
io.karatelabs.http.HttpServer
All Implemented Interfaces:
io.karatelabs.common.Stoppable, AutoCloseable

public class HttpServer extends Object implements io.karatelabs.common.Stoppable
  • Method Details

    • shutdownAll

      public static void shutdownAll()
    • start

      public static HttpServer start(int port, Function<HttpRequest,HttpResponse> handler)
    • start

      public static HttpServer start(int port, Function<HttpRequest,HttpResponse> handler, SseHandler sseHandler)
    • start

      public static HttpServer start(int port, io.netty.handler.ssl.SslContext sslContext, Function<HttpRequest,HttpResponse> handler)
    • start

      public static HttpServer start(int port, io.netty.handler.ssl.SslContext sslContext, Function<HttpRequest,HttpResponse> handler, SseHandler sseHandler)
    • start

      public static HttpServer start(int port, Function<HttpRequest,HttpResponse> handler, SseHandler sseHandler, WsHandler wsHandler)
    • start

      public static HttpServer start(int port, io.netty.handler.ssl.SslContext sslContext, Function<HttpRequest,HttpResponse> handler, SseHandler sseHandler, WsHandler wsHandler)
    • start

      public static HttpServer start(String host, int port, Function<HttpRequest,HttpResponse> handler, SseHandler sseHandler, WsHandler wsHandler)
      Start bound to a specific interface — host = "localhost"/"127.0.0.1" listens on loopback only (not reachable off-box), "0.0.0.0"/null/blank listens on every interface (the historical default). Lets a server be hardened to localhost-only; the caller (e.g. karate-max serve) decides the default per deployment (host-dev = localhost, in-container = 0.0.0.0 so Docker -p forwarding can reach it).
    • isSsl

      public boolean isSsl()
    • getPort

      public int getPort()
    • getLocalAddress

      public InetSocketAddress getLocalAddress()
      The socket address the server actually bound to — a wildcard (isAnyLocalAddress) when started with a null/blank/"0.0.0.0" host, else the specific interface (e.g. loopback for "localhost"). For diagnostics + tests of the bind-host hardening.
    • waitSync

      public void waitSync()
    • lifecycleName

      public String lifecycleName()
      Specified by:
      lifecycleName in interface io.karatelabs.common.Stoppable
    • lifecycleKind

      public String lifecycleKind()
      Specified by:
      lifecycleKind in interface io.karatelabs.common.Stoppable
    • stop

      public void stop()
      Graceful, blocking, idempotent — stopAndWait() by another name, for KarateLifecycle. Servers that wrap one of these (mock server, OAuth2 callback server) inherit registration from here and must not register themselves as well.
      Specified by:
      stop in interface io.karatelabs.common.Stoppable
    • stopAndWait

      public void stopAndWait()
    • stopAsync

      public void stopAsync()