Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I've got an issue with redirection failing from my CGI::Application when running under mod_perl.

I'm very new to mod_perl so I could well believe that I've done something wrong. My configuration for Apache2 + mod_perl is very minimal:

ServerName ... Alias /cgi-bin/ /mf/cgi-bin/ <Location /cgi-bin> SetHandler perl-script PerlHandler ModPerl::Registry PerlSendHeader On Options +ExecCGI </Location>

This works for most of my application, and appears to improve response time significantly - however there is one problem. My redirections, as coded in the CGI::Application do not work.

I've pared this down to a minimal clone of my code - I have a base class implementing a redirect method, and I have a subclass which uses that to redirect a few times.

In plain CGI-mode this works. In mod_perl it gives me the following output direct to my browser:

redirect<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>200 OK</title>
</head><body>
<h1>OK</h1>
<p>The document has moved 
<a href="http://example.com/">here</a>.</p>
<hr>
<address>Apache/2.2.9 (Debian) PHP/5.2.6-2+b1 with
 Suhosin-Patch mod_ssl/2.2.9
 OpenSSL/0.9.8g mod_musicindex/1.2.2
 mod_perl/2.0.4 Perl/v5.10.0
 Server at mail-scanning.com Port 80</address>
</body></html>

Now here is my example code which exhibits the same problem:

#!/usr/bin/perl -w use strict; use warnings; use CGI::Application; # # Base package # package Base; use base 'CGI::Application'; sub redirectPage { my ( $self, $url ) = (@_); $self->header_add( -location => $url ); $self->header_type('redirect'); } # # Derived package # package Derived; use base 'Base'; sub setup { my( $self ) = ( @_ ); $self->run_modes( homepage => 'homepage' ); $self->start_mode('homepage'); $self->mode_param('mode'); } # # Dummy method to redirect to an external site. # sub homepage { my( $self ) = ( @_ ); return ( $self->redirectPage("http://example.com/") ); } # # Instance script # package main; my $derived = new Derived(); $derived->run();

Any clues, or tips are most welcome. Any more details I can provide just ask - this is all running upon libapache2-mod-perl2, as included in Debian.

Update: - Strangly using CGI::Application::Plugin::Redirect works correctly if I change my code:

package Base; use base 'CGI::Application'; use CGI::Application::Plugin::Redirect; sub redirectPage { my ( $self, $url ) = (@_); return( $self->redirect( $url ) ); }
Steve
--

In reply to Failure to redirect when my CGI::Application powered site is used under mod_perl2 by skx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (6)
    As of 2014-07-29 02:53 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (211 votes), past polls