I use python for serving my local static site development with this custom little bash wrapper script I wrote:
#!/usr/bin/env bash
set -e; [[ $TRACE ]] && set -x
port=8080
dir="."
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "usage: http-server [PORT] [DIRECTORY]"
echo " PORT Port to listen on (default: 8080)"
echo " DIRECTORY Directory to serve (default: .)"
exit 0
fi
if [ -n "$1" ]; then
port=$1
fi
if [[ -n "$2" ]]; then
dir=$2
fi
python3 -m http.server --directory "$dir" --protocol HTTP/1.1 "$port"
For anyone baffled by this: This works because HTTP/0.9 (just called "HTTP" at the time) worked in an extremely simple way, and browsers mostly retained compatibility for this.
HTTP/0.9 web browser sends:
GET /
Netcat sends:
<!doctype html>
...
Nowadays a browser will send `GET / HTTP/1.1` and then a bunch of headers, which a true HTTP/0.9 server may be able to filter out and ignore, but of course this script will just send the document and the browser will still assume it's a legacy server.
nodesocket|10 months ago
Y_Y|10 months ago
That whole script could just be the last line! Maybe you could add defaults like
zikduruqe|10 months ago
xmodem|10 months ago
creatonez|10 months ago
HTTP/0.9 web browser sends:
Netcat sends: Nowadays a browser will send `GET / HTTP/1.1` and then a bunch of headers, which a true HTTP/0.9 server may be able to filter out and ignore, but of course this script will just send the document and the browser will still assume it's a legacy server.vFunct|10 months ago
blacksmith_tb|10 months ago
https://gist.github.com/willurd/5720255
red_admiral|10 months ago
(I'm sure if I dug in the http.server documentation I could find all those options too.)