Skip to content

Instantly share code, notes, and snippets.

@dylan4224
Last active May 16, 2018 04:13
Show Gist options
  • Save dylan4224/b956544aecf542bd98cea68e500e3687 to your computer and use it in GitHub Desktop.
Save dylan4224/b956544aecf542bd98cea68e500e3687 to your computer and use it in GitHub Desktop.
Tiny HTTP Server powered by nc
#!/usr/bin/env bash
# A Tiny HTTP Server powered by nc
port=${1:-8080}
echo "Tiny HTTP Server, listening on localhost:${port}"
while true
do
{
# Status line
echo -e 'HTTP/1.0 200 OK\r';
# Headers
echo -e 'Content-Type:text/plain\r';
echo -e '\r\n';
# Body
echo -e 'Hello, World!\n';
} | nc -l ${port}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment