#!/usr/bin/env bash
# Verify veld serves byte-correct content and well-formed headers.
set -u
BENCH=/tmp/bench
RN_BIN="$HOME/veld/target/release/veld"
pkill -f veld 2>/dev/null; sleep 1
"$RN_BIN" -c "$BENCH/veld.conf" --prefix "$BENCH" start >"$BENCH/logs/rn.log" 2>&1 &
sleep 2
echo "=== content integrity (rust :8081 vs source) ==="
for f in index.html 1k.txt 10k.txt 100k.txt 1m.txt; do
curl -s "http://127.0.0.1:8081/$f" -o "/tmp/got_$f"
if cmp -s "/tmp/got_$f" "$BENCH/html/$f"; then
echo " $f OK ($(stat -c %s "/tmp/got_$f") bytes)"
else
echo " $f MISMATCH"
fi
done
echo "=== GET headers (1k.txt) ==="
curl -sI "http://127.0.0.1:8081/1k.txt"
echo "=== HEAD (10k.txt) ==="
curl -sI -X HEAD "http://127.0.0.1:8081/10k.txt"
echo "=== 404 ==="
curl -s -o /dev/null -w "status=%{http_code}\n" "http://127.0.0.1:8081/nope.txt"
echo "=== conditional (If-None-Match) ==="
ETAG=$(curl -sI "http://127.0.0.1:8081/1k.txt" | awk '/[Ee][Tt]ag/{print $2}' | tr -d '\r')
curl -s -o /dev/null -w "revalidate status=%{http_code}\n" -H "If-None-Match: $ETAG" "http://127.0.0.1:8081/1k.txt"
echo "=== range (bytes=0-99) ==="
curl -s -o /dev/null -w "range status=%{http_code} len=%{size_download}\n" -r 0-99 "http://127.0.0.1:8081/100k.txt"
pkill -f veld 2>/dev/null