Included in this folder is a complete ThousandIsland.Handler based implementation of HTTP/1.x as defined in RFC 9112.

Process model

Within a Bandit server, an HTTP/1 connection is modeled as a single process. This process is tied to the lifecycle of the underlying TCP connection; in the case of an HTTP client which makes use of HTTP's keep-alive feature to make multiple requests on the same connection, all of these requests will be serviced by this same process.

The execution model to handle a given request is quite straightforward: the underlying Thousand Island library will call Bandit.HTTP1.Handler.handle_data/3, which will then construct a Bandit.HTTP1.Socket struct that conforms to the Bandit.HTTPTransport protocol. It will then call Bandit.Pipeline.run/3, which will go through the process of reading the request (by calling functions on the Bandit.HTTPTransport protocol), and constructing a Plug.Conn structure to represent the request and subsequently pass it to the configured Plug module.

Testing

All of this is exhaustively tested, across four files in test/bandit/http1/:

  • protocol_test.exs - network-facing aspects of the implementation, organized to follow RFC 9112's own document order
  • plug_test.exs - the Plug-facing aspects of the implementation
  • logging_test.exs - logging behavior for protocol errors and client disconnects
  • telemetry_test.exs - :telemetry event emission

Unfortunately, there is no HTTP/1 equivalent to the external h2spec test suite.