#!/bin/sh finish() { echo "Status: $1" echo "Content-type: $2" echo cat - exit } echo "$REQUEST_URI" \ | sed -nE "s#$DRASL_HEADS_ROOT/([[:xdigit:]]{32})/([[:digit:]]+)#\1 \2#p" \ | { IFS=' ' if ! read -r uuid size; then echo "Bad Request" | finish "400 Bad Request" "text/plain" fi if test "$size" -gt 64; then echo "Size Limit Exceeded" | finish "403 Forbidden" "text/plain" fi image="$(mktemp)" trap 'rm $image' EXIT if ./cache.sh ./head.sh "$uuid" "$size" 2>/dev/null > "$image"; then finish "200 OK" "image/png" < "$image" else echo "Not Found" | finish "404 Not Found" "text/plain" fi }