A small set of Go utilities and examples demonstrating low-level HTTP-over-TCP parsing and serving.
This repository contains a simple HTTP server built on top of a custom request parser and response writer, plus small helper programs for listening to raw TCP and sending UDP messages.
ref: https://www.rfc-editor.org/rfc/rfc9112
cmd/httpserver— HTTP server binary (uses the internal server to accept connections and a handler that implements a few routes).cmd/tcplistener— raw TCP listener that accepts a single connection and prints parsed request parts.cmd/udpsender— simple UDP client that reads from stdin and sends lines tolocalhost:42069.internal/headers— header parsing utilities.internal/request— request parsing from a reader (supports parsing request-line, headers and Content-Length body).internal/response— response writer helpers (status line, headers, chunked bodies, trailers).internal/server— small server wrapper that accepts TCP connections, uses the request parser and response writer, and invokes a Handler.
Default listening port: 42069 (hard-coded in the examples).
From the repository root you can build or run components directly with go run or go build.
Run the HTTP server:
go run ./cmd/httpserverOr build the binary:
go build -o bin/httpserver ./cmd/httpserver
./bin/httpserverRun the TCP listener (prints a single parsed request then exits):
go run ./cmd/tcplistenerRun the UDP sender (interactive; sends lines to localhost:42069):
go run ./cmd/udpsenderFetch the root page:
curl -v http://localhost:42069/Proxy to httpbin (example):
curl -v http://localhost:42069/httpbin/get- The project implements a custom, minimal HTTP/1.1 parser and writer for educational purposes. It understands request-lines, headers, and bodies with Content-Length; it also supports writing chunked responses and trailers.
- Header names are normalized to lowercase in
internal/headersand validated for allowed characters. - The server in
internal/serveruses the parser and writes the response buffer back to the connection after the handler returns. - The module name is
tcpgopergo.mod.
- Run
go build ./...to compile all packages and check for compile errors. - Tests can be run with
go test ./....