All links and redirects are now relative

WARNING - this might break. We'll revert this commit if so.
The rationale is for those using proxies where the host name is not proxied
on, as in Apache's ProxyPreserveHost.
RFC2161 does not permit relative Location: header, but an upcoming revision
stil in-draft will apparently allow relative spec. I believe all browsers to
support relative Location: headers already.
This commit is contained in:
Oliver Gorwits
2013-03-04 21:40:43 +00:00
parent 9848de5c26
commit e3c0ae3554
6 changed files with 21 additions and 10 deletions

View File

@@ -43,7 +43,7 @@ hook 'before_template' => sub {
if request->base->path ne '/';
# allow portable dynamic content
$tokens->{uri_for} = \&uri_for;
$tokens->{uri_for} = sub { uri_for(@_)->path_query() };
# allow very long lists of ports
$Template::Directive::WHILE_MAX = 10_000;

View File

@@ -22,23 +22,26 @@ hook 'before' => sub {
};
post '/login' => sub {
status(302);
if (param('username') and param('password')) {
my $user = schema('netdisco')->resultset('User')->find(param('username'));
if ($user) {
my $sum = Digest::MD5::md5_hex(param('password'));
if ($sum and $sum eq $user->password) {
session(user => $user->username);
redirect uri_for('/inventory');
header(Location => uri_for('/inventory')->path_query());
return;
}
}
}
redirect uri_for('/', {failed => 1});
header(Location => uri_for('/', {failed => 1})->path_query());
};
get '/logout' => sub {
session->destroy;
redirect uri_for('/', {logout => 1});
status(302);
header(Location => uri_for('/', {logout => 1})->path_query());
};
true;

View File

@@ -94,7 +94,9 @@ get '/device' => sub {
});
if (!defined $dev) {
return redirect uri_for('/', {nosuchdevice => 1});
status(302);
header(Location => uri_for('/', {nosuchdevice => 1})->path_query());
return;
}
params->{'tab'} ||= 'details';

View File

@@ -64,7 +64,11 @@ get '/search' => sub {
my $s = schema('netdisco');
if (not param('tab')) {
if (not $q) { return redirect uri_for('/') }
if (not $q) {
status(302);
header(Location => uri_for('/')->path_query());
return;
}
# pick most likely tab for initial results
if ($q =~ m/^\d+$/) {
@@ -76,11 +80,13 @@ get '/search' => sub {
if ($nd and $nd->count) {
if ($nd->count == 1) {
# redirect to device details for the one device
return redirect uri_for('/device', {
status(302);
header(Location => uri_for('/device', {
tab => 'details',
q => ($nd->first->dns || $nd->first->ip),
f => '',
});
})->path_query());
return;
}
# multiple devices