Created
December 5, 2011 17:24
-
-
Save lmatteis/1434458 to your computer and use it in GitHub Desktop.
web server in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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