From f90f2b0a67a8b9bb369b01f3993872318f2fcb18 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 27 Oct 2013 03:05:28 +0000 Subject: [PATCH] Fix redirect in Dancer to not forcibly apply scheme+host --- Netdisco/Changes | 10 ++++++++++ Netdisco/lib/App/Netdisco/Web.pm | 11 +++++++++++ Netdisco/lib/App/Netdisco/Web/AdminTask.pm | 4 +--- Netdisco/lib/App/Netdisco/Web/Device.pm | 3 +-- Netdisco/lib/App/Netdisco/Web/Search.pm | 8 +++----- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index badfa54b..c4ec352b 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -1,3 +1,13 @@ +2.019003 - + + [ENHANCEMENTS] + + * Use cursor to greatly speed up macsuck/arpnip startup code (jeneric) + + [BUG FIXES] + + * Fix redirect in Dancer to not forcibly apply scheme+host + 2.019002 - 2013-10-24 [BUG FIXES] diff --git a/Netdisco/lib/App/Netdisco/Web.pm b/Netdisco/lib/App/Netdisco/Web.pm index 22430c0e..548c3c36 100644 --- a/Netdisco/lib/App/Netdisco/Web.pm +++ b/Netdisco/lib/App/Netdisco/Web.pm @@ -100,4 +100,15 @@ any qr{.*} => sub { template 'index'; }; +{ + # https://github.com/PerlDancer/Dancer/issues/967 + no warnings 'redefine'; + *Dancer::_redirect = sub { + my ($destination, $status) = @_; + my $response = Dancer::SharedData->response; + $response->status($status || 302); + $response->headers('Location' => $destination); + }; +} + true; diff --git a/Netdisco/lib/App/Netdisco/Web/AdminTask.pm b/Netdisco/lib/App/Netdisco/Web/AdminTask.pm index 4ca0ea5f..3a600d2a 100644 --- a/Netdisco/lib/App/Netdisco/Web/AdminTask.pm +++ b/Netdisco/lib/App/Netdisco/Web/AdminTask.pm @@ -55,9 +55,7 @@ foreach my $jobtype (keys %jobs_all, keys %jobs) { if exists $jobs{$jobtype} and not param('device'); add_job($jobtype, param('device'), param('extra')); - - header(Location => uri_for('/admin/jobqueue')->path); - return status(302); + redirect uri_for('/admin/jobqueue')->path; }; } diff --git a/Netdisco/lib/App/Netdisco/Web/Device.pm b/Netdisco/lib/App/Netdisco/Web/Device.pm index 475cbac2..63574069 100644 --- a/Netdisco/lib/App/Netdisco/Web/Device.pm +++ b/Netdisco/lib/App/Netdisco/Web/Device.pm @@ -159,8 +159,7 @@ get '/device' => require_login sub { }); if (!defined $dev) { - header(Location => uri_for('/', {nosuchdevice => 1})->path_query); - return status(302); + return redirect uri_for('/', {nosuchdevice => 1})->path_query; } params->{'tab'} ||= 'details'; diff --git a/Netdisco/lib/App/Netdisco/Web/Search.pm b/Netdisco/lib/App/Netdisco/Web/Search.pm index 2b5155bb..92f48675 100644 --- a/Netdisco/lib/App/Netdisco/Web/Search.pm +++ b/Netdisco/lib/App/Netdisco/Web/Search.pm @@ -66,8 +66,7 @@ get '/search' => require_login sub { if (not param('tab')) { if (not $q) { - header(Location => uri_for('/')->path); - return status(302); + return redirect uri_for('/')->path; } # pick most likely tab for initial results @@ -80,12 +79,11 @@ get '/search' => require_login sub { if ($nd and $nd->count) { if ($nd->count == 1) { # redirect to device details for the one device - header(Location => uri_for('/device', { + return redirect uri_for('/device', { tab => 'details', q => ($nd->first->dns || $nd->first->ip), f => '', - })->path_query); - return status(302); + })->path_query; } # multiple devices