From: David Baird Date: Fri, 4 Nov 2005 16:08:13 +0000 (+0000) Subject: minor refactoring of redirect_request X-Git-Tag: 2.11~106 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=3239e23cfde1714927e043e6e72dc38d7b20e1c3;p=maypole.git minor refactoring of redirect_request git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@412 48953598-375a-da11-a14b-00016c27c3ee --- diff --git a/lib/Apache/MVC.pm b/lib/Apache/MVC.pm index 84454bc..3ee8541 100644 --- a/lib/Apache/MVC.pm +++ b/lib/Apache/MVC.pm @@ -86,16 +86,6 @@ sub get_request { $self->ar($ar); } -=item get_protocol - -=cut - -sub get_protocol { - my $self = shift; - my $protocol = ( $self->ar->protocol =~ m/https/i ) ? 'https' : 'http' ; - return $protocol; -} - =item parse_location =cut @@ -140,8 +130,9 @@ sub parse_args { =cut # FIXME: use headers_in to gather host and other information? -sub redirect_request { - my $self = shift; +sub redirect_request +{ + my $r = shift; my $redirect_url = $_[0]; my $status = "302"; if ($_[1]) { @@ -149,20 +140,29 @@ sub redirect_request { if ($args{url}) { $redirect_url = $args{url}; } else { - my $path = $args{path} || $self->path; - my $host = $args{domain} || $self->ar->hostname; - my $protocol = $args{protocol} || - ( $self->ar->protocol =~ m/https/i ) ? 'https' : 'http' ; + my $path = $args{path} || $r->path; + my $host = $args{domain} || $r->ar->hostname; + my $protocol = $args{protocol} || $r->get_protocol; $redirect_url = "${protocol}://${host}/${path}"; } $status = $args{status} if ($args{status}); } - $self->headers_out->set('Status' => $status); - $self->headers_out->set('Location' => $redirect_url); + $r->headers_out->set('Status' => $status); + $r->headers_out->set('Location' => $redirect_url); return OK; } +=item get_protocol + +=cut + +sub get_protocol { + my $self = shift; + my $protocol = ( $self->ar->protocol =~ m/https/i ) ? 'https' : 'http' ; + return $protocol; +} + =item send_output =cut diff --git a/lib/CGI/Maypole.pm b/lib/CGI/Maypole.pm index 27b74f2..9b2ee79 100644 --- a/lib/CGI/Maypole.pm +++ b/lib/CGI/Maypole.pm @@ -76,17 +76,6 @@ sub get_request shift->cgi( CGI::Simple->new ); } -=item get_protocol - -=cut - -sub get_protocol -{ - my $self = shift; - my $protocol = ($self->cgi->https) ? 'https' : 'http'; - return $protocol; -} - =item parse_location =cut @@ -150,7 +139,7 @@ sub redirect_request my $path = $args{path} || $r->cgi->url(-absolute => 1, -query=>1); my $host = $args{domain}; ($host = $r->cgi->url(-base => 1)) =~ s/^https?:\/\///i unless ($host); - my $protocol = $args{protocol} || ($r->cgi->https()) ? 'https' : 'http'; + my $protocol = $args{protocol} || $r->get_protocol; $redirect_url = "${protocol}://${host}/${path}"; } $status = $args{status} if ($args{status}); @@ -162,6 +151,17 @@ sub redirect_request return; } +=item get_protocol + +=cut + +sub get_protocol +{ + my $self = shift; + my $protocol = ($self->cgi->https) ? 'https' : 'http'; + return $protocol; +} + =item send_output =cut