aboutsummaryrefslogtreecommitdiff
path: root/scripts/httpsvr
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2024-01-20 12:31:58 -0500
committerMitchell Riedstra <mitch@riedstra.dev>2024-01-20 12:31:58 -0500
commite2a0cf2a79b43f9f86b74270f3d96fe300687804 (patch)
treea87edf55f81e78f4d0968d6f006562090260e068 /scripts/httpsvr
parentec83443853116b07f18fbef8c6de31cf157939a0 (diff)
downloaddotfiles-e2a0cf2a79b43f9f86b74270f3d96fe300687804.tar.gz
dotfiles-e2a0cf2a79b43f9f86b74270f3d96fe300687804.tar.xz
Cleanup unused files and code.
Diffstat (limited to 'scripts/httpsvr')
-rwxr-xr-xscripts/httpsvr68
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