blob: d74ac9bdacb2f60e35f0d08ccae5c32c6ea0e5fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#!/bin/sh
PHTTP_CACHE=${PHTTP_CACHE:-/dev/shm/phttp}
mkdir -p $PHTTP_CACHE/meta $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/meta/$BASENAME) $PHTTP_CACHE/files/$BASENAME"
return
}
local META
META=$(curl -sL -w "%{content_type} %{url_effective}\n" $@ -o "$PHTTP_CACHE/files/$BASENAME") && {
META="$(echo $META | rev | cut -d/ -f2- | rev)/"
echo "$META $PHTTP_CACHE/files/$BASENAME"
echo "$META" > $PHTTP_CACHE/meta/$BASENAME
return
}
return 1
}
get_with_arguments $@
|