HTTP/1.1 Protocol State Machine #
This module implements the core HTTP/1.1 protocol state machine that handles parsing requests/responses and generating output. The machine is direction-aware, supporting both server mode (receiving requests) and client mode (receiving responses).
Results from a single step of the state machine.
Events that occurred during this step (e.g., headers received, control flow, errors).
- output : Internal.ChunkedBuffer
Output data ready to be sent to the socket.
Instances For
The HTTP/1.1 protocol state machine.
- reader : Reader dir
The state of the reader.
- writer : Writer dir
The state of the writer.
- config : Config
The configuration.
Events that happened during reading and writing.
Error thrown by the machine.
- instant : Option (Time.DateTime Time.TimeZone.UTC)
The timestamp for the
Dateheader. - keepAlive : Bool
If the connection will be kept alive after the message.
- forcedFlush : Bool
Whether a forced flush has been requested by the user.
- pullBodyStalled : Bool
Set when a previous
pullBodycall could not make progress in.readBody. Cleared on new input or state reset.
Instances For
Returns true if the reader has completed successfully.
Equations
- machine.isReaderComplete = match machine.reader.state with | Std.Http.Protocol.H1.Reader.State.complete => true | x => false
Instances For
Returns true if the reader is closed.
Equations
- machine.isReaderClosed = match machine.reader.state with | Std.Http.Protocol.H1.Reader.State.closed => true | x => false
Instances For
Returns true when the reader is paused waiting for a canContinue decision
(server-side only; always false on the client side).
Equations
- machine_2.isReaderAwaitingContinue = true
- machine.isReaderAwaitingContinue = false
Instances For
Returns true if the machine should flush buffered output.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Returns true if the writer is waiting for headers of a new message.
Equations
- machine.isWaitingMessage = decide ((machine.writer.state == Std.Http.Protocol.H1.Writer.State.waitingHeaders) = true ∧ ¬machine.writer.sentMessage = true)
Instances For
Returns true if both reader and writer are closed and no output remains.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Returns true when pullBody can attempt to produce body data immediately.
Equations
- machine.canPullBody = (!Std.Http.Protocol.H1.Machine.drainBodyInternally✝ machine && match machine.reader.state with | Std.Http.Protocol.H1.Reader.State.readBody a => true | x => false)
Instances For
Returns true when pullBody is currently expected to make progress.
Equations
- machine.canPullBodyNow = (machine.canPullBody && !machine.pullBodyStalled)
Instances For
Signals EOF on the reader's input without changing the reader state.
Used internally for flow control (e.g., after rejecting Expect: 100-continue).
To also transition the reader to .closed, follow this with setReaderState .closed.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Closes the writer side, preventing any further message output.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Signals that the user is not sending data anymore.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Signals that the socket is not sending data anymore.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Set a known size for the message body, replacing any previous value.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Suppresses writing body bytes for the current outgoing message while keeping header generation active. Used for responses that must not carry payload bytes.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Send the head of a message to the machine.
Must only be called when machine.isWaitingMessage is true. If called in any
other state (e.g. called twice), the machine panics.
Informational (1xx) responses are written directly to the output buffer; the writer
stays in waitingHeaders so the application can send additional interim responses or
the final response. The reader state is not affected — use canContinue to resolve
an Expect: 100-continue decision separately.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Resolves an Expect: 100-continue decision.
When status is 100 Continue, sends the interim response and advances to body
reading. For any other status, sends the rejection response (typically 417), disables
keep-alive, and closes the reader — the body will not be received.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Sends an error response with Connection: close and shuts down input.
If the machine is waiting to send a message, sends status with a Connection: close
header and signals that the body is done (letting the step function encode and flush the
response), then stops accepting further input. Otherwise, closes the writer directly and
stops accepting further input.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Takes and clears accumulated output bytes, returning them as a buffer.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Advances writer-side state machine by one logical transition.
Depending on writer state, this may:
- request an application answer,
- serialize headers,
- flush fixed/chunked body bytes,
- finalize/close after completion.
Advances reader-side state machine by one logical transition.
Dispatches parsing work according to current reader state (start-line, headers, body, completion, or failure handling).
Execute one step of the state machine.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Pulls at most one body chunk from the reader.
It advances body parsing until it either:
- produces a chunk (
some PulledChunk), or - cannot continue for now (
none).
Equations
- One or more equations did not get rendered due to their size.