Documentation

Std.Http.Server

HTTP Server #

This module defines a simple, asynchronous HTTP/1.1 server implementation.

It provides the Std.Http.Server structure, which encapsulates all server state, and functions for starting, managing, and gracefully shutting down the server.

The server runs entirely using Async and uses a shared CancellationContext to signal shutdowns. Each active client connection is tracked, and the server automatically resolves its shutdown promise once all connections have closed.

The Server structure holds all state required to manage the lifecycle of an HTTP server, including connection tracking and shutdown coordination.

  • The context used for shutting down all connections and the server.

  • activeConnections : Mutex Nat

    Active HTTP connections

  • connectionLimit : Option Semaphore

    Semaphore used to enforce the maximum number of simultaneous active connections. none means no connection limit.

  • shutdownPromise : Channel Unit

    Indicates when the server has successfully shut down.

  • config : Config

    Configuration of the server

  • The local socket address the server is bound to. When serve is called with a port of 0, this reflects the ephemeral port assigned by the OS rather than the requested address. none for servers constructed without an associated listening socket (e.g. serveConnection).

Instances For
    def Std.Http.Server.new (config : Config := { }) (localAddr : Option Net.SocketAddress := none) :

    Create a new Server structure with an optional configuration.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      @[inline]

      Triggers cancellation of all requests and the accept loop in the server. This function should be used in conjunction with waitShutdown to properly coordinate the shutdown sequence.

      Equations
      Instances For
        @[inline]

        Waits for the server to shut down. Blocks until another task or async operation calls the shutdown function.

        Equations
        Instances For
          @[inline]

          Returns a Selector that waits for the server to shut down.

          Equations
          Instances For
            @[inline]

            Triggers cancellation of all requests and the accept loop, then waits for the server to fully shut down. This is a convenience function combining shutdown and then waitShutdown.

            Equations
            Instances For
              def Std.Http.Server.serve {σ : Type} [Handler σ] (addr : Net.SocketAddress) (handler : σ) (config : Config := { }) (backlog : UInt32 := 1024) :

              Start a new HTTP/1.1 server on the given socket address. This function uses Async to handle tasks and TCP connections, and returns a Server structure that can be used to cancel the server.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For