perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Torsten Foertsch <>
Subject Re: content_type in SSI- or directly-called mp2 scripts
Date Wed, 17 Dec 2008 09:07:22 GMT
On Wed 17 Dec 2008, wrote:
> My mod_perl2 scripts mostly fall into 2 categories:
> 1) scripts that are called by URL location, and generate complete  
> content-pages
> 2) scripts that are called by SSI "include virtual" sequences  
> in .html files, and generate part of a page
> In some cases scripts of type 1 directly call scripts of type 2 to  
> generate parts of their pages.
> (Call this "case 3").
> My questions are about when to call $r->content_type('text/html')
> Such a call is a good idea in category 1, right?

Each request has a content-type assigned no matter if you set it in your 
script or not. Normally (for static files), that header if figured out 
by one of the mime-modules (mod_mime, mod_mime_magic) in the 
type-checker-phase of the request cycle. But usually it's a good idea 
to set/reset it in your content handler prior to sending any data to 
the client because that handler knows better what it is going to send. 

> Such a call probably should not be made by the directly-called script
>   in case 3, right?
> Apache probably can't even tell that a new script has gotten into the
>   act, the calling
> and called script are both in the undifferentiated sea of mod-perl  
> code, right?
> In an SSI-invoked script (category 2) is a content_type call a)  
> required, b) good practice,
> or c) a bad idea?

In all cases it is good practice. Virtual include uses subrequests. That 
means when the INCLUDE filter sees a vinclude it stops the output of 
the current request, creates a subrequest for the wanted document, runs 
that document sending the output to the client but ignoring all headers 
save the status. When the subrequest is done the output of the main 
request is resumed. So, in your cases 2 and 3 the Content-Type header 
is ignored. The client sees only the content-type of the main request.

If your included script wants to know the content-type of the main 
request it can use $r->main->content_type (perhaps to adopt the 
character set).


Need professional mod_perl support?
Just hire me:

View raw message