Geoffrey Young wrote:
> Steve Hay wrote:
>> The code is written in a very out-moded style: it is compatible with
>> mod_cgi, runs via ModPerl::Registry (formerly Apache::Registry), and
>> produces all its output via explicit print() statements scattered
>> left, right and centre, including a print() statement to send the
>> response headers. An error-handling subroutine calls
>> $r->bytes_sent() to find out if anything has been sent yet, so that
>> it knows whether or not it needs to send response headers before
>> sending an error page (it could be invoked either before or after
>> the headers have been sent in the normal course of events).
>>
>> This works fine under mod_perl1, but under mod_perl2 I find that the
>> error-handler always emits response headers itself (i.e. it always
>> thinks that nothing has been sent yet). Therefore, in those cases
>> where response headers have already been sent, I now have a second
>> set being sent, which the user ends up seeing in the web browser.
>> The code in question is simply:
>>
>> unless (exists $ENV{MOD_PERL}
>> ? Apache2::RequestUtil->request()->bytes_sent()
>> : tell STDOUT)
>> {
>> #... send response headers
>
> since you no longer send response headers in mp2, isn't this all moot?
Did you overlook the fact that I'm running all this through
ModPerl::Registry, or am I overlooking something?
My httpd.conf section looks like this:
<Location /cgi-bin>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
</Location>
Admittedly, with the "PerlOptions +ParseHeaders" in there I do see two
sets of the response headers that I want to set (Content-Language and
Content-Type) in the output (for a "normal" request in which no error
has occurred):
Connection: close
Date: Thu, 02 Aug 2007 16:59:03 GMT
Server: Apache/2.2.4 (Win32) mod_perl/2.0.3 Perl/v5.8.8
Content-Language: en-GB
Content-Language: en-GB
Content-Type: text/html; charset=windows-1252
Content-Type: text/html; charset=windows-1252
Client-Date: Thu, 02 Aug 2007 16:59:03 GMT
Client-Peer: 10.23.50.54:8088
Client-Response-Num: 1
Client-Transfer-Encoding: chunked
Link: </radview/radview.css>; rel="stylesheet"; type="text/css"
Title: Radview Home Page
<HTML>
...
but without "PerlOptions +ParseHeaders" the headers output by httpd just
specify a text/plain response and my headers end up in the message body:
Connection: close
Date: Thu, 02 Aug 2007 16:59:35 GMT
Server: Apache/2.2.4 (Win32) mod_perl/2.0.3 Perl/v5.8.8
Content-Type: text/plain
Client-Date: Thu, 02 Aug 2007 16:59:35 GMT
Client-Peer: 10.23.50.54:8088
Client-Response-Num: 1
Client-Transfer-Encoding: chunked
Content-Language: en-GB
Content-Type: text/html; charset=windows-1252
<HTML>
...
If I don't print my Content-Language and Content-Type headers at all
then, of course, they don't end up in the get output at all:
Connection: close
Date: Thu, 02 Aug 2007 17:05:43 GMT
Server: Apache/2.2.4 (Win32) mod_perl/2.0.3 Perl/v5.8.8
Content-Type: text/plain
Client-Date: Thu, 02 Aug 2007 17:05:44 GMT
Client-Peer: 10.23.50.54:8088
Client-Response-Num: 1
Client-Transfer-Encoding: chunked
<HTML>
...