@@ -20,7 +20,14 @@ A "low-level" HTTP 1.1 Server and Client implementation for Lean. It is designed
2020# Overview
2121
2222This module of the standard library defines many concepts related to the HTTP protocol
23- and its semantics in a SANS-IO format. The main function of this library is `Std.Http.Server.serve`,
23+ and its semantics in a sans I/O format.
24+
25+ **sans I/O** means that the core logic of the library doesn’t perform any actual input/output itself,
26+ it just defines how data *should* be processed. This separation allows the protocol implementation
27+ to remain pure and testable, while different transports (like TCP sockets or mocks) can handle
28+ the actual reading and writing of bytes.
29+
30+ The main function of this library is `Std.Http.Server.serve`,
2431located in the module `Std.Internal.Http.Server`. It starts a simple HTTP/1.1 server that
2532handles all requests and sends them to a simple handler function. It uses the default `Std.Internal.Async`
2633library, but it can be customized to use whatever IO library you want, as the protocol implementation
@@ -29,14 +36,6 @@ is pure.
2936If you want to customize how your server handles sockets, you can use `Std.Http.Server.serveConnection`,
3037which is a simple function to bind a handler to a `Transport`.
3138
32- # Low-Level Protocol Implementation
33-
34- This library provides a low-level foundation that allows you to implement your own IO layer on top
35- of it. The core protocol parsing and generation logic is available in `Std.Internal.Http.Protocol`,
36- which provides pure functions for HTTP message parsing and serialization. This design allows you to
37- integrate the HTTP protocol handling with any IO system or networking library of your choice, while
38- reusing the robust protocol implementation.
39-
4039# Minimal Example
4140
4241```lean
@@ -63,26 +62,19 @@ def main := mainAsync.block
6362
6463## Transport
6564
66- `Std.Http.Server.Transport` is a type class used for describing a way of communication between a `Connection` and outside
67- of the `Connection` . It can be a `Mock.Client` that sends and receives byte arrays so it can be used for
68- deterministic testing a HTTP connection or a `TCP.Socket.Client` that is how usually it communicated with
69- the internet.
65+ `Std.Http.Server.Transport` is a type class that defines how communication occurs between a `Connection`
66+ and the outside world . It can be implemented by, for example, a `Mock.Client`, which sends and receives
67+ byte arrays for deterministic HTTP connection testing, or by a `TCP.Socket.Client`, which is the
68+ standard way to communicate over the internet in HTTP/1.1 .
7069
7170## Connection
7271
73- `Std.Http.Server.Connection` is a structure that stores both a `Transport` and a `Machine`
74- the machine right now is only a `Protocol.H1.Machine` that implements a State Machine for parsing request and responses for HTTP/1.1
72+ `Std.Http.Server.Connection` is a structure that holds both a `Transport` and a `Machine`. Currently,
73+ the machine is a `Protocol.H1.Machine`, which implements the state machine responsible for parsing HTTP/1.1
74+ requests and responses.
7575
7676If you want to customize how your server handles sockets, you can use `Std.Http.Server.serveConnection`,
77- which is a simple function to bind a handler to a `ClientConnection`.
78-
79- # Low-Level Protocol Implementation
80-
81- This library provides a low-level foundation that allows you to implement your own IO layer on top
82- of it. The core protocol parsing and generation logic is available in `Std.Internal.Http.Protocol`,
83- which provides pure functions for HTTP message parsing and serialization. This design allows you to
84- integrate the HTTP protocol handling with any IO system or networking library of your choice, while
85- reusing the robust protocol implementation.
77+ a simple function that binds a handler to a `ClientConnection`.
8678
8779# Minimal Example
8880
@@ -100,10 +92,9 @@ def handler (req : Request Body) : Async (Response Body) := do
10092 return Response.ok ("hi, " ++ data)
10193
10294def mainAsync : Async Unit := do
103- Server.serve (.v4 (.mk (.ofParts 0 0 0 0) 8080)) handler
95+ let server ← Server.serve (.v4 (.mk (.ofParts 0 0 0 0) 8080)) handler
96+ server.waitShutdown
10497
10598def main := mainAsync.block
10699```
107100-/
108-
109- namespace Std.Http
0 commit comments