From 72a44cfcaa74534eb5e00c6b17a8b6ff187d0d5e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 23 Apr 2013 15:33:58 +0200 Subject: [PATCH] Make negative narinfo responses much smaller --- src/lib/Hydra/Controller/Root.pm | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 3d49072d..ac927df9 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -215,19 +215,20 @@ sub nix_cache_info :Path('nix-cache-info') :Args(0) { } -sub hashToPath { - my ($c, $hash) = @_; - die if length($hash) != 32; - my $path = queryPathFromHashPart($hash); - notFound($c, "Store path with hash ‘$hash’ does not exist.") unless $path; - return $path; -} - - sub narinfo :LocalRegex('^([a-z0-9]+).narinfo$') :Args(0) { my ($self, $c) = @_; my $hash = $c->req->captures->[0]; - $c->stash->{storePath} = hashToPath($c, $hash); + + die if length($hash) != 32; + my $path = queryPathFromHashPart($hash); + + if (!$path) { + $c->response->content_type('text/plain'); + $c->stash->{'plain'}->{'data'} = "does not exist\n"; + $c->forward('Hydra::View::Plain'); + } + + $c->stash->{storePath} = $path; $c->stash->{current_view} = 'NARInfo'; }