mod_perl, CGI and stacked content handlers

Colin Kuskie ckuskie at dalsemi.com
Thu Jun 21 18:55:56 CDT 2001


Hey, Mongers!

I've been using a hacked up version of Lincoln Steins original
Apache::NavBar module for wrapping a header, footer and navigation
around HTML pages from my server.  Now I'd like to add some CGI scripts
(search engine, etc.) and have found several hiccups:

----------------------------------------------------------------

1) $r->content_type() and CGI.
With a simple test CGI script:

#!/usr/local/bin/perl

use strict;
use CGI qw/:standard/;

print header();
print start_html();
print "hello world\n";
print end_html;

The beginning of the handler(warn statement for debugging) says that
the content type of the request is empty (not sure whether undefined or
null)

sub handler {
  my $r = shift;
  warn "CT: ", $r->content_type, "\n";
  $r->content_type eq 'text/html' || return DECLINED;

Is that because the content type for the request object is set by the
file type and since there's no physical file associated with CGI output
it's unknown?

I hesitate just to assign a default type since some future CGI's will
be outputting graphics.  I'd hoped that Apache would look at the header
and determine the content_type from there.

----------------------------------------------------------------

2) Apache::OutputChain and per-request configurations

Apache::NavBar is great; I can set per directory or per file
configurations for headers, footers and navigation.  However, when I
used Apache::OutputChain to cause the output of the CGI to be filtered
by it, the object that gets passed to the PRINT method is not the
Apache object, but a pseudo-object from the Apache::NavBar class.
(Note, I left the code at home otherwise I'd post the code and setup
below this.  If people are interested in taking a peek I'll remember to
bring it in tomorrow)

This means that after I bypassed the content checking that I was still
unable to wrap the CGI output because the code had nowhere to look (in
other words, $r->dir_config('MyVar') couldn't be resolved by
Apache::NavBar).

Have any of you come across and already dealt with something like
this?  Is there an easier way to get a solution to my overall problem?
Do I need to go out and buy a book (other than the Writing Apache
Modules in Perl and C book that I bought yesterday)?  Should I wait
until mod_perl supports the Filter API in Apache 2.0?

Thenks,
Colin Kuskie
TIMTOWTDI



More information about the Pdx-pm-list mailing list