48 lines
1.2 KiB
Markdown
48 lines
1.2 KiB
Markdown
# go-http-server
|
||
|
||
A minimal TCP-based HTTP server in Go for learning and experimentation. It demonstrates manual request-line and header parsing and simple connection handling.
|
||
|
||
Requires
|
||
- Go 1.26 or newer.
|
||
|
||
Quick start
|
||
1. Build
|
||
- cd into the project root (the directory that contains `go-http-server`) and run:
|
||
```
|
||
cd go-http-server
|
||
go build -o go-http-server
|
||
```
|
||
2. Run
|
||
- Start the server:
|
||
```
|
||
./go-http-server
|
||
```
|
||
- Or during development:
|
||
```
|
||
go run .
|
||
```
|
||
|
||
Testing
|
||
- Run unit tests:
|
||
```
|
||
cd go-http-server
|
||
go test ./...
|
||
```
|
||
|
||
What’s in the repo
|
||
- `main.go` — listener and connection lifecycle.
|
||
- `readheaders.go` — `readHeaders` and `parseRequestLine` logic; returns a `Headers` struct.
|
||
- `response_helper` — helpers for writing responses.
|
||
- `config` — runtime configuration (listen address, profiling toggle).
|
||
|
||
Notes
|
||
- The parser expects a request-line with exactly three tokens: `METHOD URI PROTO`.
|
||
- Header lines without a colon are ignored; values are trimmed.
|
||
- The server supports simple keep-alive behavior when the `Connection: keep-alive` header is present.
|
||
|
||
Contributing
|
||
- Open issues or PRs. Add tests for parsing or new behavior and run `go test ./...` before submitting.
|
||
|
||
License
|
||
- MIT
|