http-go is my own implementation of HTTP/1.1 server directly on top of Go’s standard TCP layer.
This library covers all essential parts of HTTP/1.1 protocol, including parsing the request line and headers, according to RFC 9110 and RFC 9112. It handles the message body, either Content-Length or transfer-chunked encoding behaviour. Furthermore, it implements the structured handling system to customize the respective response error type.
The library also supports proxy requests.
Warning
This is not a comprehensive library, e.g. it is not able to parse multi-line headers.
http-go/
├── cmd/httpserver/
│ └── main.go # Entry point for running the HTTP server
│── internal/
│ ├── server/ # Listens, connection loop, handler dispatch
│ ├── constants.go # Contains the definition of consants used for the internal package
│ ├── headers.go # Creates the generic header map for parsing the headers
│ ├── http_message.go # Creates an interface for the HTTP message, reads the HTTP message
│ ├── parser.go # Parses the HTTP message based on the state of the parser
│ ├── request.go # Parses the request
│ ├── response.go # Parses the response, writes the response and performes chunked encoding
└── README.md- TCP
- UDP
- RFC 7231 – An active and widely referenced RFC.
- RFC 9112 – Easier to read than RFC 7231, relies on understanding from RFC 9110.
- RFC 9110 – Covers HTTP "semantics."
- RFC 2616 – Deprecated by RFC 7231.
- Custom request parser using a state machine
- Support for request line, headers, CRLF parsing, and message bodies
- Custom response writer, including:
- Status line
- Headers
- Body
- Chunked body
- Chunked Transfer-Encoding writer:
- Writes chunk size as a hexa decimal number
- Writes data in the form of chunks
- Writes terminating line
- Proxy Handler
- Built-in proxy routing for paths like:
- /httpbin/x → https://httpbin.org/x
- Built-in proxy routing for paths like:
- Install Go
Ensure Go ≥ 1.20 is installed.- Run the HTTP server
go run cmd/httpserver/main.go- Make a request by using curl command
curl -v localhost:42069- Raw HTTP over netcat (nc)
echo -e "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n" | nc localhost 42069- Make a proxy request
curl -v localhost:42069/httpbin/stream/10A typical HTTP response looks like:
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 13
Hello World!A chunked HTTP response looks like:
HTTP/1.1 200 OK
Content-Type: text/plain
Transfer-Encoding: chunked
7
Welcome
1c
to Mozilla Developer Network
0This project was built while following the Boot.dev "Build an HTTP Server in Go" course: BOOT.DEV
Note
Also this doc is not generated by AI, i like using emojis. 😉