Skip to content

Instantly share code, notes, and snippets.

@ooharak
Created August 28, 2014 13:27
Show Gist options
  • Save ooharak/807363e3d28b953fde16 to your computer and use it in GitHub Desktop.
Save ooharak/807363e3d28b953fde16 to your computer and use it in GitHub Desktop.
usage: ./ashttp.sh 'text/html;charset=utf-8' < index.html | nc -l 8080
#!/bin/sh
if [ $# -eq 0 ]; then
mime='text/plain;charset=utf-8'
else
mime="$1"
fi
CR=$'\x0d'
cat <<EOF | sed -e "s/\$/$CR/g"
HTTP/1.0 200 OK
Content-Type: $mime
EOF
cat
@ooharak
Copy link
Author

ooharak commented Aug 28, 2014

A toy HTTP Server

while true; do
  ./ashttp.sh 'text/html;charset=utf-8' < index.html | nc -l 8080
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment