httpd: allow to set hostname and port as first and second argument - randomcrap - random crap programs of varying quality
(HTM) git clone git://git.codemadness.org/randomcrap
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit a02adcfc771484c6b70503d1f25f03680f1402a1
(DIR) parent 0ed15f361ed9749a92676826bbf91fc88d5eddea
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Fri, 15 Aug 2025 14:06:35 +0200
httpd: allow to set hostname and port as first and second argument
print configuration on startup:
host, port, htdocsdir and scriptdir.
Diffstat:
M minihttpd/httpd.sh | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
---
(DIR) diff --git a/minihttpd/httpd.sh b/minihttpd/httpd.sh
@@ -82,14 +82,17 @@ sanitizepath() {
printf '%s' "$1" | sed 's@\.\./@@;s@\./@@g'
}
-if test "$1" = ""; then
- script="$(readlink -f "$0")"
- socat TCP4-LISTEN:8080,reuseaddr,fork "SYSTEM:'$script httpd'"
-elif test "$1" = "httpd"; then
- rootdir="$(dirname "$(readlink -f "$0")")"
- htdocsdir="${rootdir}/htdocs"
- scriptdir="${rootdir}/cgi-bin"
+script="$(readlink -f "$0")"
+rootdir="$(dirname "$(readlink -f "$0")")"
+htdocsdir="${rootdir}/htdocs"
+scriptdir="${rootdir}/cgi-bin"
+if test "$1" != "httpd"; then
+ export SERVER_NAME="${1:-127.0.0.1}"
+ export SERVER_PORT="${2:-8080}"
+ printf 'started httpd:\n\nhost=%s\nport=%s\nhtdocs=%s\nscriptdir=%s\n\n' "$SERVER_NAME" "$SERVER_PORT" "$htdocsdir" "$scriptdir" >&2
+ SOCAT_SOCKADDR="${SERVER_NAME}" socat "TCP4-LISTEN:${SERVER_PORT},reuseaddr,fork,bind=${SERVER_NAME}" "SYSTEM:'$script httpd'"
+elif test "$1" = "httpd"; then
IFS=" " read -r method request proto
while IFS=": " read -r key value; do
test "$value" = "" && break