content_type in SSI- or directly-called mp2 scripts
am 17.12.2008 03:11:45 von Craig
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?
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?
Thanks,
cmac
www.animalhead.com
Re: content_type in SSI- or directly-called mp2 scripts
am 17.12.2008 10:07:22 von torsten.foertsch
On Wed 17 Dec 2008, craig@animalhead.com wrote:
> My mod_perl2 scripts mostly fall into 2 categories:
>
> 1) scripts that are called by URL location, and generate complete =A0
> content-pages
> 2) scripts that are called by SSI "include virtual" sequences =A0
> in .html files, and generate part of a page
>
> In some cases scripts of type 1 directly call scripts of type 2 to =A0
> 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=20
script or not. Normally (for static files), that header if figured out=20
by one of the mime-modules (mod_mime, mod_mime_magic) in the=20
type-checker-phase of the request cycle. But usually it's a good idea=20
to set/reset it in your content handler prior to sending any data to=20
the client because that handler knows better what it is going to send.=20
> Such a call probably should not be made by the directly-called script
> =A0 in case 3, right?
> Apache probably can't even tell that a new script has gotten into the
> =A0 act, the calling
> and called script are both in the undifferentiated sea of mod-perl =A0
> code, right?
>
> In an SSI-invoked script (category 2) is a content_type call a) =A0
> required, b) good practice,
> or c) a bad idea?
In all cases it is good practice. Virtual include uses subrequests. That=20
means when the INCLUDE filter sees a vinclude it stops the output of=20
the current request, creates a subrequest for the wanted document, runs=20
that document sending the output to the client but ignoring all headers=20
save the status. When the subrequest is done the output of the main=20
request is resumed. So, in your cases 2 and 3 the Content-Type header=20
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=20
request it can use $r->main->content_type (perhaps to adopt the=20
character set).
Torsten
=2D-=20
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net