Skip to content

HTTPServer

[Source]

HTTP protocol handler that manages parsing, response queuing, and connection lifecycle for a single HTTP connection.

Stored as a field inside an HTTPServerActor. Handles all HTTP-level concerns — parsing incoming data, URI validation, response queue management, idle timeout scheduling, and backpressure — and delivers HTTP events to the actor via HTTPServerLifecycleEventReceiver callbacks.

The protocol class implements lori's ServerLifecycleEventReceiver to receive TCP-level events from the connection, processes them through the HTTP parser, and forwards HTTP-level events to the owning actor.

Use none() as the field default so that this is ref in the actor constructor body, then replace with create() or ssl():

actor MyServer is HTTPServerActor
  var _http: HTTPServer = HTTPServer.none()

  new create(auth: lori.TCPServerAuth, fd: U32,
    config: ServerConfig)
  =>
    _http = HTTPServer(auth, fd, this, config)
class ref HTTPServer is
  ServerLifecycleEventReceiver ref,
  _RequestParserNotify ref,
  _ResponseQueueNotify ref

Implements


Constructors

none

[Source]

Create a placeholder protocol instance.

Used as the default value for the _http field in HTTPServerActor implementations, allowing this to be ref in the actor constructor body. The placeholder is immediately replaced by create() or ssl() — its methods must never be called.

new ref none()
: HTTPServer ref^

Returns


create

[Source]

Create the protocol handler for a plain HTTP connection.

Called inside the HTTPServerActor constructor. The server_actor parameter must be the actor's this — it provides the HTTPServerLifecycleEventReceiver ref for synchronous HTTP callbacks.

new ref create(
  auth: TCPServerAuth val,
  fd: U32 val,
  server_actor: HTTPServerActor ref,
  config: ServerConfig val)
: HTTPServer ref^

Parameters

Returns


ssl

[Source]

Create the protocol handler for an HTTPS connection.

Like create, but wraps the TCP connection in SSL using the provided SSLContext. Called inside the HTTPServerActor constructor for HTTPS connections.

new ref ssl(
  auth: TCPServerAuth val,
  ssl_ctx: SSLContext val,
  fd: U32 val,
  server_actor: HTTPServerActor ref,
  config: ServerConfig val)
: HTTPServer ref^

Parameters

Returns


Public Functions

request_received

[Source]

fun ref request_received(
  method: Method val,
  raw_uri: String val,
  version: ((HTTP10 val | HTTP11 val) & _Version val),
  headers: Headers val)
: None val

Parameters

Returns


body_chunk

[Source]

fun ref body_chunk(
  data: Array[U8 val] val)
: None val

Parameters

Returns


request_complete

[Source]

fun ref request_complete()
: None val

Returns


parse_error

[Source]

fun ref parse_error(
  err: (TooLarge val | UnknownMethod val | InvalidURI val | 
    InvalidVersion val | MalformedHeaders val | InvalidContentLength val | 
    InvalidChunk val | BodyTooLarge val))
: None val

Parameters

Returns


close

[Source]

Close the connection from the server actor.

Use this when the actor needs to force-close the connection — for example, after rejecting a request early (413 Payload Too Large) via the Responder delivered in on_request(). Safe to call at any time; idempotent due to the _Active state guard.

fun ref close()
: None val

Returns


yield_read

[Source]

Request the read loop to exit after the current callback returns, giving other actors a chance to run. Reading resumes automatically in the next scheduler turn — no explicit action is needed.

Call this from HTTP callbacks (on_request, on_body_chunk, on_request_complete) to implement yield policies such as yielding every N requests during pipelining storms or every N bytes of body data.

Operates at the TCP level: it prevents the next socket read, not the processing of already-buffered data. If a single receive delivers a buffer containing multiple pipelined requests, all are parsed and all callbacks fire before the yield takes effect.

fun ref yield_read()
: None val

Returns