minimal web server using netcat on mac

command

1
2
3
4
5
6
7
8
9
#: netcat / BSD
while true; do
echo "HTTP/1.1 200 OK\n\nHello $(id -un)\nCurrent time $(date)" | nc -l 6666 -c
done

#: netcat / GNU
while true; do
echo "HTTP/1.1 200 OK\n\nHello $(id -un)\nCurrent time $(date)" | nc -l -p 6666 -c
done

test

1
2
3
4
5
6
7
8
9
10
11
> curl -i localhost:6666
HTTP/1.1 200 OK

Hello liusha
Current time Mon Dec 11 15:37:20 CST 2017

#: netcat console
GET / HTTP/1.1
Host: localhost:6666
User-Agent: curl/7.54.0
Accept: */*