rfe: choice of type of redirect on redirect assets

This commit is contained in:
JT Smith 2008-09-16 17:51:15 +00:00
parent fc7fbfbd0c
commit 6e04c4b705
5 changed files with 85 additions and 30 deletions

View file

@ -16,6 +16,7 @@ package WebGUI::Session::Http;
use strict;
use WebGUI::Utility;
=head1 NAME
@ -231,7 +232,7 @@ Returns a boolean value indicating whether the current page will redirect to som
sub isRedirect {
my $self = shift;
return ($self->getStatus() eq "302");
return isIn($self->getStatus(), qw(302 301));
}
@ -279,7 +280,7 @@ sub sendHeader {
my %params;
if ($self->isRedirect()) {
$request->headers_out->set(Location => $self->getRedirectLocation);
$request->status(301);
$request->status($self->getStatus);
} else {
$request->content_type($self->getMimeType);
my $cacheControl = $self->getCacheControl;
@ -494,7 +495,7 @@ sub setNoHeader {
#-------------------------------------------------------------------
=head2 setRedirect ( url )
=head2 setRedirect ( url, [ type ] )
Sets the necessary information in the HTTP header to redirect to another URL.
@ -502,16 +503,21 @@ Sets the necessary information in the HTTP header to redirect to another URL.
The URL to redirect to.
=head3 type
Defaults to 302 (temporary redirect), but you can optionally set 301 (permanent redirect).
=cut
sub setRedirect {
my $self = shift;
my $url = shift;
my $type = shift || 302;
my @params = $self->session->form->param;
return undef if ($url eq $self->session->url->page() && scalar(@params) < 1); # prevent redirecting to self
$self->session->errorHandler->info("Redirecting to $url");
$self->setRedirectLocation($url);
$self->setStatus("302", "Redirect");
$self->setStatus($type, "Redirect");
$self->session->style->setMeta({"http-equiv"=>"refresh",content=>"0; URL=".$url});
}