l go: quote everything, cleanup
This commit is contained in:
parent
1a066ef070
commit
7def09c525
@ -31,11 +31,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATEDIR=$HOME
|
STATEDIR=$HOME
|
||||||
mkdir -p $STATEDIR/items
|
mkdir -p "$STATEDIR/items"
|
||||||
|
|
||||||
case "$Method $Request_URI" in
|
case "$Method $Request_URI" in
|
||||||
"GET /"*)
|
"GET /"*)
|
||||||
if item=$(find_item ''${Request_URI#/}); then
|
if item=$(find_item "''${Request_URI#/}"); then
|
||||||
uri=$(cat "$item")
|
uri=$(cat "$item")
|
||||||
printf 'HTTP/1.1 302 Found\r\n'
|
printf 'HTTP/1.1 302 Found\r\n'
|
||||||
printf 'Content-Type: text/plain\r\n'
|
printf 'Content-Type: text/plain\r\n'
|
||||||
@ -45,26 +45,27 @@
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
"POST /") #{ "uri": "http://nixos.org" }
|
"POST /")
|
||||||
uri=$(mktemp -t htgen.$$.content.XXXXXXXX)
|
uri=$(mktemp -t htgen.$$.content.XXXXXXXX)
|
||||||
trap "rm $uri >&2" EXIT
|
trap 'rm $uri >&2' EXIT
|
||||||
|
|
||||||
head -c $req_content_length \
|
head -c "$req_content_length" \
|
||||||
| grep -Eo 'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)' \
|
| grep -Eo 'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)' \
|
||||||
|
| head -1 \
|
||||||
> $uri
|
> $uri
|
||||||
sha256=$(sha256sum -b $uri | cut -d\ -f1)
|
sha256=$(sha256sum -b "$uri" | cut -d\ -f1)
|
||||||
base32=$(${pkgs.nixStable}/bin/nix-hash --to-base32 --type sha256 $sha256)
|
base32=$(${pkgs.nixStable}/bin/nix-hash --to-base32 --type sha256 "$sha256")
|
||||||
item=$STATEDIR/items/$base32
|
item="$STATEDIR/items/$base32"
|
||||||
ref=http://$req_host/$base32
|
ref="http://$req_host/$base32"
|
||||||
|
|
||||||
if ! test -e $item; then
|
if ! test -e "$item"; then
|
||||||
mkdir -v -p $STATEDIR/items >&2
|
mkdir -v -p "$STATEDIR/items" >&2
|
||||||
cp -v $uri $item >&2
|
cp -v $uri "$item" >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
base32short=$(echo $base32 | cut -b-7)
|
base32short=$(echo "$base32" | cut -b-7)
|
||||||
if item=$(find_item $base32short); then
|
if item=$(find_item "$base32short"); then
|
||||||
ref=$(echo "http://$req_host/$base32short")
|
ref="http://$req_host/$base32short"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf 'HTTP/1.1 200 OK\r\n'
|
printf 'HTTP/1.1 200 OK\r\n'
|
||||||
|
Loading…
Reference in New Issue
Block a user