Return proper 404 when path is missing

This commit is contained in:
Michael Raskin 2015-01-03 16:55:56 +03:00
parent 60d0005a0c
commit 187646f071

View file

@ -10,13 +10,18 @@ KEYNAME=na
export NIX_REMOTE=daemon
config="${NIX_BINARY_CACHE_CONFIG:-${HTTP_NIX_BINARY_CACHE_CONFIG:-/etc/nix/nix-binary-cache.cgi.conf}}"
config="$(cd "$(@coreutils@/dirname "$config")";
config="$(cd "$(@coreutils@/dirname "$config")";
@coreutils@/pwd)/$(@coreutils@/basename "$config")"
@coreutils@/test -e "$config" && . "$config"
header(){
echo "Content-Type: text/plain; charset=utf-8"
echo
echo
}
header404(){
echo "Status: 404 Not Found"
echo
}
clean_path() {
@ -28,12 +33,12 @@ storeq(){
}
sign(){
test -n "$1" &&
@coreutils@/sha256sum | @gnused@/sed -e 's/ .*//' |
test -n "$1" &&
@coreutils@/sha256sum | @gnused@/sed -e 's/ .*//' |
@openssl@/openssl rsautl -sign -inkey "$@" | @coreutils@/base64 -w 0
}
case "$QUERY_STRING" in
case "$QUERY_STRING" in
"")
header
echo "Hello, this is a dynamically-generated Nix binary cache"
@ -61,9 +66,9 @@ case "$QUERY_STRING" in
echo "Compression: $COMPRESSION"
echo "NarHash: $(storeq --hash "$path")"
echo "NarSize: $(storeq --size "$path")"
echo "References: $(storeq --references "$path" |
echo "References: $(storeq --references "$path" |
@coreutils@/tac | clean_path )"
echo "Deriver: $(storeq --deriver "$path" |
echo "Deriver: $(storeq --deriver "$path" |
clean_path )"
)"
signature="$(echo "$info" | sign "$KEY")"
@ -72,6 +77,7 @@ case "$QUERY_STRING" in
echo "Signature: 1;$KEYNAME;$signature"
else
header404
exit 1
fi
;;
@ -81,6 +87,7 @@ case "$QUERY_STRING" in
header
@nix@/nix-store --dump "$path" | @xz@/xz
else
header404
exit 1
fi
;;
@ -91,6 +98,7 @@ case "$QUERY_STRING" in
header
@nix@/nix-store --dump "$path" | @bzip2@/bzip2
else
header404
exit 1
fi
;;