Files
kapow/poc/bin/static
Roberto Abdelkader Martínez Pérez f6ce9935a5 Adapt bin/static to new binary structure
2019-09-05 08:32:34 +02:00

22 lines
504 B
Bash
Executable File

#!/bin/sh
BASE="$1"
PATHNAME="$2"
REAL="$(realpath --relative-base="$BASE" "$BASE/$PATHNAME")"
if [ ! -f "$BASE/$PATHNAME" ]; then
kapow set /response/status 404
exit
else
case $REAL in
"/"*)
kapow set /response/status 403
exit
;;
*)
kapow set /response/status 200
kapow set /response/headers/Content-Type "$(python -m mimetypes "$BASE/$REAL" | awk '/type:/ {print $2; exit 0}; !/type:/ {print "application/octet-stream"}')"
kapow set /response/body < "$BASE/$REAL"
esac
fi