Skip to content

Instantly share code, notes, and snippets.

@juji
Last active May 31, 2017 06:37
Show Gist options
  • Save juji/37d413f5cd19b4e433e8592880f07531 to your computer and use it in GitHub Desktop.
Save juji/37d413f5cd19b4e433e8592880f07531 to your computer and use it in GitHub Desktop.
bash 5 line server
#!/usr/bin/env bash
# usage:
# ./server.sh [port] [response]
#
RESPONSE="HTTP/1.1 200 OK\r\nConnection: keep-alive\r\n\r\n${2:-"OK"}\r\n"
while { echo -en "$RESPONSE"; } | nc -q 0 -l -p "${1:-8080}"; do
echo "================================================"
echo "you can do stuff on request"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment