Phoenix.pm: mod_perl internal redirect question

Scott Walters scott at illogics.org
Wed Jan 8 10:42:44 CST 2003


Doug and folks,

Sorry, I don't have time to read the docs and I haven't delt with this 
before, but I thought I would make a few general statements.

CGI.pm is going to read the post off of STDIN. This is something that
cannot be undone. You don't have the browser-caching-the-get-string
problem, so if you don't have large fields, this is an acceptable
solution. It should also be noted that if you don't use CGI to
read the post request, it will still be waiting there in STDIN
for the CGI application you redirect to to read. In other words,
don't read the POST data and it will still be POST data.

I'm assuming you don't want to modify the source of the
application you're posting to, but I still want to note that using
something like Apache::Session (but not Apache::Session) is cleaner -
stick the user data in a session-specific container and let things
access it there. Finally, I'm going to note why I don't use mod_perl -
I hate having a small number of threads/processes, and each costs a
lot using Apache/mod_perl. I'm in love with thttpd (which runs as
a single process which services any number - even thousands
of concurrent requests) and plain old CGI or redirects to a
FastCGI-like server. I'm sure mod_perl can't be changed in your
project, but I thought I would throw stones at it anyway. 

I have a copy of Programming Apache Modules with Perl and C if
you'd like to barrow it, or perhaps I'll make time in a bit here...

Good to see that you aren't shackled up in the dungeon full time
and they let you out =)

-scott


> 
> 
> Hi all!
> 
> This is a question for all you mod_perl experts out there.  I am 
> attempting to do an internal redirect in mod_perl, preserving any POST 
> request parameters that might be kicking around.  I couldn't get the 
> example code I found here:
> 
> http://www.esc.auckland.ac.nz/Docs/mod_perl/snippets.html#Redirect_a_POST_request_forward
> 
> to work.  It appeared to do the redirect, but wouldn't pass any of the 
> POST parameters.  To complicate matters, I'm using Apache::Request 
> (which is a subclass of Apache) instead of the default Apache object.  I 
> did finally get the redirect to work, but only by building up my own 
> query string and appending it to the URL being redirected to.  This 
> works fine, but I'd really like to know why the other code doesn't work. 
>   The commented out code is the code in question.  The only other change 
> is to remove the appending of the parameters.  Any ideas are appreciated.
> 
> # redirect #############################################################
> 
> sub redirect
> {
>    use Apache::Constants qw(M_GET);
> 
>    my $self = shift;
> 
>    my %tag_parameter = @_;
> 
>    my @parameters;
> 
>    foreach my $parameter ($self->request->param)
>    {
> 
>      push
>      (
>        @parameters,
>        uri_escape($parameter) .  '=' .
>          uri_escape($self->request->param($parameter))
>      );
> 
>    }
> 
>    my $parameters = join('&', @parameters);
> 
> # Don't know why this doesn't work.  Appending parameters to URL below 
> does. ???
> 
> #  my $content = $self->request->content;
> #  $self->request->method('GET');
> #  $self->request->method_number(M_GET);
> #  $self->request->headers_in->unset("Content-length");
> #  $self->request->args($parameters);
> #  my $content = $self->request->content;
> 
>    $self->
>      request->
>        internal_redirect
>        (
>          $self->normalize_absolute_path("/pcms/$tag_parameter{'url'}") .
>            "?$parameters"
>        );
> 
> } # END: redirect
> 
> 




More information about the Phoenix-pm mailing list