Skip to content

Instantly share code, notes, and snippets.

@lmatteis
Created December 5, 2011 17:24
Show Gist options
  • Save lmatteis/1434458 to your computer and use it in GitHub Desktop.
Save lmatteis/1434458 to your computer and use it in GitHub Desktop.
web server in bash
#!/bin/bash
read request # this will read the first line of input
#while /bin/true; do
# read header
# [ "$header" == $'\r' ] && break;
#done
#
# how do i read the rest?
i dont fucking know
echo -e ${request}
x="${request#GET }"
filename=".${x% HTTP/*}"
if [ -f "$filename" ]; then echo -e "HTTP/1.1 200 OK\r"
echo -e "Content-Type: `/usr/bin/file -bi \"$filename\"`\r"
echo -e "\r"
cat "$filename"
echo -e "\r"
else
echo -e "HTTP/1.1 404 Not Found\r"
echo -e "Content-Type: text/html\r"
echo -e "\r"
echo -e "404 Not Found\r"
echo -e "Not Found
The requested resource was not found\r"
echo -e "\r"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment