Documentation

Std.Http.Protocol.H1

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 : Array (Event dir)

    Events that occurred during this step (e.g., headers received, control flow, errors).

  • 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.

    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 : Array (Event dir)

        Events that happened during reading and writing.

      • error : Option Error

        Error thrown by the machine.

      • The timestamp for the Date header.

      • 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 pullBody call could not make progress in .readBody. Cleared on new input or state reset.

      Instances For
        @[inline]

        Returns true if the reader is in a failed state.

        Equations
        Instances For
          @[inline]

          Returns true if the reader has completed successfully.

          Equations
          Instances For
            @[inline]

            Returns true if the reader is closed.

            Equations
            Instances For
              @[inline]

              Returns true when the reader is paused waiting for a canContinue decision (server-side only; always false on the client side).

              Equations
              Instances For
                @[inline]

                Returns true if the machine should flush buffered output.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  @[inline]

                  Returns true if the writer is waiting for headers of a new message.

                  Equations
                  Instances For
                    @[inline]

                    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
                      @[inline]

                      Returns true when pullBody can attempt to produce body data immediately.

                      Equations
                      Instances For
                        @[inline]

                        Returns true when pullBody is currently expected to make progress.

                        Equations
                        Instances For
                          @[inline]
                          def Std.Http.Protocol.H1.Machine.feed {dir : Direction} (machine : Machine dir) (data : ByteArray) :

                          Feeds input bytes into the reader side of the machine.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            @[inline]

                            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
                              @[inline]

                              Closes the writer side, preventing any further message output.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                @[inline]

                                Signals that the user is not sending data anymore.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  @[inline]

                                  Signals that the socket is not sending data anymore.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    @[inline]

                                    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
                                      @[inline]
                                      def Std.Http.Protocol.H1.Machine.suppressOutgoingBody {dir : Direction} (machine : Machine dir) (forceZero : Bool := false) :

                                      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
                                        @[inline]
                                        def Std.Http.Protocol.H1.Machine.send {dir : Direction} (machine : Machine dir) (message : Message.Head dir.swap) :

                                        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
                                          def Std.Http.Protocol.H1.Machine.canContinue {dir : Direction} (machine : Machine dir) (status : Status) :

                                          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
                                              @[inline]
                                              def Std.Http.Protocol.H1.Machine.sendData {dir : Direction} (machine : Machine dir) (data : Array Chunk) :

                                              Enqueues body chunks into the writer buffer for encoding and sending.

                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              Instances For
                                                @[inline]

                                                Takes and clears all accumulated events, returning the drained array.

                                                Equations
                                                • One or more equations did not get rendered due to their size.
                                                Instances For
                                                  @[inline]

                                                  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
                                                    partial def Std.Http.Protocol.H1.Machine.processWrite {dir : Direction} (machine : Machine dir) :

                                                    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.
                                                    partial def Std.Http.Protocol.H1.Machine.processRead {dir : Direction} (machine : Machine dir) :

                                                    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
                                                      @[inline]

                                                      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.
                                                      Instances For