acompiled

The catalog contains seeded project examples. Your workspace stores your own projects and conversations.

zeroeight/tiny-http

Public
Star9

An HTTP/1.0 server for Linux in x86-64 assembly. No libc; every build starts it and curls it.

Code
Blame·2 commits across 28 linesoldernewer
Route table: /, /health, and a 404 for everything elseAug 23 2# Starts the server on a spare port, asks it for three things, and checks
3# every answer. Run from the repository root after a build.
5port=$((20000 + $$ % 20000))
6./build/tiny-http "$port" &
7pid=$!
8trap 'kill "$pid" 2>/dev/null' EXIT INT TERM
9url="http://127.0.0.1:$port"
10
11for i in 1 2 3 4 5 6 7 8 9 10; do
Route table: /, /health, and a 404 for everything elseAug 23 12 curl -s -o /dev/null "$url/health" && break
14done
15
16fail() { echo "FAIL: $*"; exit 1; }
17
18curl -s -i "$url/" | head -n 1 | grep -q '200 OK' || fail "GET / did not answer 200"
19echo "GET / 200"
20
Route table: /, /health, and a 404 for everything elseAug 23 21[ "$(curl -s "$url/health")" = "ok" ] || fail "GET /health did not say ok"
22echo "GET /health 200, ok"
23
24code=$(curl -s -o /dev/null -w '%{http_code}' "$url/no/such/page")
25[ "$code" = 404 ] || fail "GET /no/such/page answered $code, not 404"
26echo "GET /no/... 404"
27
28echo "smoke: 3 requests answered"