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