summaryrefslogtreecommitdiff
path: root/phttp
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2020-08-06 19:39:27 +0200
committerAki <please@ignore.pl>2020-08-06 19:39:27 +0200
commit983fb04ca74a08b7e297f02a7eefb1cb98e9d063 (patch)
treedab5fd10248329e0292b006448bc353f4485b895 /phttp
parentb9eb466d129227afaa3db7f89232bf911d024728 (diff)
downloadbrowse-983fb04ca74a08b7e297f02a7eefb1cb98e9d063.zip
browse-983fb04ca74a08b7e297f02a7eefb1cb98e9d063.tar.gz
browse-983fb04ca74a08b7e297f02a7eefb1cb98e9d063.tar.bz2
Added very initial implementation of protocol daemon for http
Diffstat (limited to 'phttp')
-rwxr-xr-xphttp26
1 files changed, 26 insertions, 0 deletions
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 $@