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
A single body chunk produced by a pull-driven read.
- final : Bool
Whether this chunk finishes the current body stream.
- incomplete : Bool
Whether the chunk data is partial for the current frame/body slice (more bytes are still required to complete it).
- chunk : Chunk
The pulled body chunk. Chunked framing is removed; other transfer codings, such as the
gzipofTransfer-Encoding: gzip, are not decoded. A server rejects a request with a coding that is not inConfig.acceptedTransferCodings.
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.
- date : Option Header.Value
The
Datefield value a server writes in each final response whose head has none, including the error responses the machine writes itself (RFC 9110 §6.6.1). The caller keeps it current; withnone, noDateis added. - keepAlive : Bool
If the connection will be kept alive after the message.
- 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_3.isReaderAwaitingContinue = true
- machine_1.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 = (machine.writer.state == Std.Http.Protocol.H1.Writer.State.waitingHeaders)
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
Stops taking input without changing the reader state: input already buffered is still parsed, then
the reader ends as at EOF. 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 peer closed its side of the connection, so no more input will arrive.
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, or dropped when the
request is HTTP/1.0; 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.
A Content-Length in the head gives the length of a body set as chunked, whose length is unknown.
A head whose Content-Length or Transfer-Encoding otherwise contradicts the length set with
setKnownSize, or describes no length, is not written: a server answers 500 Internal Server Error and closes the connection, and a client ends the exchange. Both emit .failed with an
.other error, set error and close the reader, so the machine halts.
A response without content (to HEAD, or a 204, 205 or 304) cannot contradict it, and a HEAD response
advertises the Content-Length of its head.
A message HTTP/1.0 cannot frame (see unframeableForHttp10) is rejected the same way. A 2xx to
CONNECT is written without content or framing fields, and the connection then closes.
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) with a short
text/plain explanation, unless a final response was already sent, 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.
- machine_3.canContinue status = machine_3
- machine_3.canContinue status = machine_3
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 a short text/plain explanation (letting the step function encode and flush the
response), then stops accepting further input. Otherwise, closes the writer directly, ends
keep-alive 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.