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 is in a failed state.
Instances For
Returns true if the reader has completed successfully.
Instances For
Returns true if the reader is closed.
Instances For
Returns true when the reader is paused waiting for a canContinue decision
(server-side only; always false on the client side).
Instances For
Returns true if the machine should flush buffered output.
Instances For
Returns true if the writer is waiting for headers of a new message.
Instances For
Returns true if both reader and writer are closed and no output remains.
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.
Instances For
Closes the writer side, preventing any further message output.
Instances For
Signals that the user is not sending data anymore.
Instances For
Signals that the socket is not sending data anymore.
Instances For
Set a known size for the message body, replacing any previous value.
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.
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.
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.
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.
Instances For
Takes and clears accumulated output bytes, returning them as a buffer.
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.
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).