HTTPClientConnection¶
HTTP protocol handler that manages request serialization, response parsing, and connection lifecycle for a single HTTP client connection.
Stored as a field inside an HTTPClientConnectionActor. Handles all
HTTP-level concerns — serializing outgoing requests, parsing incoming
responses, idle timeout scheduling, and backpressure — and delivers
HTTP events to the actor via HTTPClientLifecycleEventReceiver callbacks.
The protocol class implements lori's ClientLifecycleEventReceiver
to receive TCP-level events from the connection, and
_ResponseParserNotify to receive parser callbacks. It 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 MyClient is HTTPClientConnectionActor
var _http: HTTPClientConnection = HTTPClientConnection.none()
new create(auth: lori.TCPConnectAuth, host: String, port: String,
config: ClientConnectionConfig)
=>
_http = HTTPClientConnection(auth, host, port, this, config)
Implements¶
- ClientLifecycleEventReceiver ref
- _ResponseParserNotify ref
Constructors¶
none¶
Create a placeholder protocol instance.
Used as the default value for the _http field in
HTTPClientConnectionActor 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¶
- HTTPClientConnection ref^
create¶
Create the protocol handler for a plain HTTP connection.
Called inside the HTTPClientConnectionActor constructor. The
client_actor parameter must be the actor's this — it provides the
HTTPClientLifecycleEventReceiver ref for synchronous HTTP callbacks.
new ref create(
auth: TCPConnectAuth val,
host: String val,
port: String val,
client_actor: HTTPClientConnectionActor ref,
config: ClientConnectionConfig val)
: HTTPClientConnection ref^
Parameters¶
- auth: TCPConnectAuth val
- host: String val
- port: String val
- client_actor: HTTPClientConnectionActor ref
- config: ClientConnectionConfig val
Returns¶
- HTTPClientConnection 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 HTTPClientConnectionActor constructor
for HTTPS connections.
new ref ssl(
auth: TCPConnectAuth val,
ssl_ctx: SSLContext val,
host: String val,
port: String val,
client_actor: HTTPClientConnectionActor ref,
config: ClientConnectionConfig val)
: HTTPClientConnection ref^
Parameters¶
- auth: TCPConnectAuth val
- ssl_ctx: SSLContext val
- host: String val
- port: String val
- client_actor: HTTPClientConnectionActor ref
- config: ClientConnectionConfig val
Returns¶
- HTTPClientConnection ref^
Public Functions¶
send_request¶
Serialize and send an HTTP request.
Returns SendRequestOK on success, ConnectionClosed if the connection
is not open, or ResponsePending if a response to a previous request
is still in progress.
Auto-sets Host and Content-Length headers during serialization if
they are not already present in the request.
fun ref send_request(
request: HTTPRequest val)
: (SendRequestOK val | ConnectionClosed val | ResponsePending val)
Parameters¶
- request: HTTPRequest val
Returns¶
- (SendRequestOK val | ConnectionClosed val | ResponsePending val)
close¶
Close the connection.
Safe to call at any time; idempotent due to the _Active state guard
in _close_connection().
Returns¶
- None val
yield_read¶
Exit the read loop after the current callback, giving other actors a chance to run. Reading resumes automatically on the next scheduler turn.
Intended for use inside on_body_chunk() to prevent a single large
response from starving other actors. Granularity is per-TCP-read, not
per-HTTP-chunk — one TCP read may contain multiple chunks, and they will
all be parsed before yielding. This is a one-shot flag; there is no
corresponding "unmute" needed.
No state guard is needed — if the connection is closed, the read loop is not running and the flag is harmless.
Returns¶
- None val
response_received¶
fun ref response_received(
status: U16 val,
reason: String val,
version: ((HTTP10 val | HTTP11 val) & _Version val),
headers: Headers val)
: None val
Parameters¶
- status: U16 val
- reason: String val
- version: ((HTTP10 val | HTTP11 val) & _Version val)
- headers: Headers val
Returns¶
- None val
body_chunk¶
Parameters¶
Returns¶
- None val
response_complete¶
Returns¶
- None val
parse_error¶
fun ref parse_error(
err: (TooLarge val | InvalidStatusLine val | InvalidVersion val |
MalformedHeaders val | InvalidContentLength val | InvalidChunk val |
BodyTooLarge val))
: None val
Parameters¶
- err: (TooLarge val | InvalidStatusLine val | InvalidVersion val | MalformedHeaders val | InvalidContentLength val | InvalidChunk val | BodyTooLarge val)
Returns¶
- None val