HTTPServer¶
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[RuntimeBackend ref] ref,
_RequestParserNotify ref,
_ResponseQueueNotify ref
Implements¶
- ServerLifecycleEventReceiver[RuntimeBackend ref] ref
- _RequestParserNotify ref
- _ResponseQueueNotify ref
Constructors¶
none¶
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.
Returns¶
- HTTPServer ref^
create¶
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¶
- auth: TCPServerAuth val
- fd: U32 val
- server_actor: HTTPServerActor ref
- config: ServerConfig val
Returns¶
- HTTPServer ref^
ssl¶
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¶
- auth: TCPServerAuth val
- ssl_ctx: SSLContext val
- fd: U32 val
- server_actor: HTTPServerActor ref
- config: ServerConfig val
Returns¶
- HTTPServer ref^
Public Functions¶
request_received¶
Validate and deliver a parsed HTTP request.
Rejects requests that violate Host header rules (RFC 9110 §7.2 / RFC 9112 §3.2) or have inconsistent request-target and Host authorities.
fun ref request_received(
method: Method val,
raw_uri: String val,
version: Version,
headers: Headers val)
: None val
Parameters¶
Returns¶
- None val
body_chunk¶
Parameters¶
Returns¶
- None val
request_complete¶
Returns¶
- None val
parse_error¶
Parameters¶
- err: ParseError
Returns¶
- None val
close¶
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:
the first call starts the close, and a call made once the connection is
closing or closed does nothing.
Returns¶
- None val
set_timer¶
Create a one-shot timer that fires on_timer() after the configured
duration. Returns a TimerToken on success, or a SetTimerError on
failure.
Unlike idle timeout, this timer has no I/O-reset behavior — send and
receive activity do not change when it comes due. A timer set here still
fires if the connection starts closing before it comes due. There is no
automatic re-arming; call set_timer() again from on_timer() for
repetition.
Only one timer can be active at a time. Setting a timer while one is
already active returns SetTimerAlreadyActive — call cancel_timer()
first. Requires the connection to be open; returns SetTimerNotOpen if
not.
A successfully returned TimerToken may still fail asynchronously if
the underlying ASIO subscription is lost — see on_timer_failure().
Use lori.MakeTimerDuration(milliseconds) to create the duration value.
Parameters¶
- duration: TimerDuration
Returns¶
- (TimerToken val | SetTimerError)
cancel_timer¶
Cancel an active timer. No-op if the token doesn't match the active timer (already fired, already cancelled, wrong token). Safe to call with stale tokens.
Parameters¶
- token: TimerToken val
Returns¶
- None val