From 983fb04ca74a08b7e297f02a7eefb1cb98e9d063 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Aug 2020 19:39:27 +0200 Subject: Added very initial implementation of protocol daemon for http --- phttp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 phttp diff --git a/phttp b/phttp new file mode 100755 index 0000000..eb69732 --- /dev/null +++ b/phttp @@ -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 $@ -- cgit v1.1