X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FCGI%2FMaypole.pm;h=dda15fcd7a52df6c8dabd3616b4bb22223d1e77a;hb=ac7eb8f3a1780223d5376e623ab90af3c8f83f04;hp=27b74f261d4cf4bf20c1d1c01a0efe47c0d39dcc;hpb=3d8147141cf009d244c8fde36da4a84b6a8b52d4;p=maypole.git diff --git a/lib/CGI/Maypole.pm b/lib/CGI/Maypole.pm index 27b74f2..dda15fc 100644 --- a/lib/CGI/Maypole.pm +++ b/lib/CGI/Maypole.pm @@ -7,9 +7,9 @@ use CGI::Simple; use Maypole::Headers; use Maypole::Constants; -our $VERSION = '2.10'; +our $VERSION = '2.11'; -__PACKAGE__->mk_accessors( qw( cgi ) ); +__PACKAGE__->mk_accessors( qw/cgi/ ); =head1 NAME @@ -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 @@ -103,12 +92,18 @@ sub parse_location $r->headers_in->set($field_name => $cgi->http($http_header)); } + $r->preprocess_location(); + my $path = $cgi->url( -absolute => 1, -path_info => 1 ); my $loc = $cgi->url( -absolute => 1 ); { no warnings 'uninitialized'; $path .= '/' if $path eq $loc; - $path =~ s/^($loc)?\///; + if ($loc =~ /\/$/) { + $path =~ s/^($loc)?//; + } else { + $path =~ s/^($loc)?\///; + } } $r->path($path); @@ -116,6 +111,17 @@ sub parse_location $r->parse_args; } +=item warn + +=cut + +sub warn { + my ($self,@args) = @_; + my ($package, $line) = (caller)[0,2]; + warn "[$package line $line] ", @args ; + return; +} + =item parse_args =cut @@ -150,7 +156,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,14 +168,41 @@ 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 +Generates output (using C) and prints it. + =cut sub send_output { my $r = shift; + print $r->collect_output; +} + +=item collect_output + +Gathers headers and output together into a string and returns it. +Splitting this code out of C supports L. + +=cut + +sub collect_output +{ + my $r = shift; + # Collect HTTP headers my %headers = ( -type => $r->content_type, @@ -181,7 +214,7 @@ sub send_output $headers{"-$_"} = $r->headers_out->get($_); } - print $r->cgi->header(%headers), $r->output; + return $r->cgi->header(%headers) . $r->output; } =item get_template_root