Files
kapow/poc/bin/static
Roberto Abdelkader Martínez Pérez 34e35bbcbf Fixed wrong /request path.
2019-06-12 07:35:39 +02:00

22 lines
454 B
Bash
Executable File

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