diff options
Diffstat (limited to 'scripts/httpsvr')
| -rwxr-xr-x | scripts/httpsvr | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/scripts/httpsvr b/scripts/httpsvr deleted file mode 100755 index ffc816a..0000000 --- a/scripts/httpsvr +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/sh -# Stupid basic http server using OpenBSD netcat -set -e - -PORT="${PORT:-8900}" -ADDR="${ADDR:-127.0.0.1}" - -ncpid= - -send_index() { -cat <<EOF -HTTP/1.1 200 OK -Server: shell -Content-Type: text/html; charset=UTF-8 - -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="UTF-8"> - <title>Netcat HTTP</title> -</head> -<body> - Minimal HTTP server in posix SH and OpenBSD's netcat -</body> -</html> -EOF -} - -cleanup() { - set +e - kill "$ncpid" >/dev/null 2>&1 - rm "$_f" "$_inF" >/dev/null 2>&1 - exit 0 -} -trap cleanup EXIT INT - -while true ; do - _f="$(mktemp)" - - _inF="$(mktemp)" - rm -f "$_inF" - mkfifo "$_inF" - - #shellcheck disable=SC2002 - cat "$_inF" | nc -l "$ADDR" "$PORT" > "$_f" & # | tee /dev/fd/2 >"$_f" & - ncpid=$! - - counter=0 - while [ $counter -lt 100 ] || [ -s "$_f" ] ; do - if grep -qi "^Accept:" "$_f" ; then - pth="$(sed -nre 's@^GET ([^ ][^ ]*) HTTP/1.1.*@\1@gp' < "$_f")" - - echo "Request for path: $pth" - - case $pth in - /) send_index >"$_inF" ;; - esac - - break - fi - sleep .01 - [ -s "$_f" ] && counter=$((counter += 1)) - ps $ncpid >/dev/null 2>&1 || break - done - - kill $ncpid || echo "" - rm "$_f" "$_inF" -done |
