Takes http request as input and outputs the headers and their values as json. Exits just before reading the request body. Doesn't parse query parameters from the path though. It's on the TODO list.
bash
(optional) mktemp
and jq
Run a simple http server in foreground in a terminal:
ncat \
-c './httparse >/dev/tty ;printf "HTTP/1.1 200 OK\r\n"; timeout 1 cat >/dev/tty' \
-kl 8080
In another terminal:
curl localhost:8080 -d "Hello server"$'\r\n'
See what you got in the first terminal :-)
Now, open http://localhost:8080 in a browser and check the new output at the first terminal.
The demo-server provided, uses httparse
. Shows any POST/PUT payload on the server terminal, and greets client on GET.
Run the server on port 8080 as:
ncat -e './demo-server' -kl 8080
Open http://localhost:8080 in a browser.
Or, post a simple payload using cURL:
curl localhost:8080 -d "Hello server"