diff options
-rwxr-xr-x | phttp | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -0,0 +1,26 @@ +#!/bin/sh +PHTTP_CACHE=${PHTTP_CACHE:-/dev/shm/phttp} +mkdir -p $PHTTP_CACHE/mimes $PHTTP_CACHE/files || exit 1 + +make_sum() { + echo "$@" | sha512sum | head -c72 + echo +} + +get_with_arguments() { + local BASENAME + BASENAME=$(make_sum $@) + [ -e $PHTTP_CACHE/files/$BASENAME ] && { + echo "$(cat $PHTTP_CACHE/mimes/$BASENAME) $PHTTP_CACHE/files/$BASENAME" + return + } + local TYPE + TYPE=$(curl -sL -w "%{content_type}\n" $@ -o "$PHTTP_CACHE/files/$BASENAME") && { + echo "$TYPE $PHTTP_CACHE/files/$BASENAME" + echo "$TYPE" > $PHTTP_CACHE/mimes/$BASENAME + return + } + return 1 +} + +get_with_arguments $@ |