I've got a program that I want to run under Apache::Registry, or mod_cgi if
mod_perl is not installed.
The problem, some of you may remember, is that even though I was sending
Status: 304 Not Modified
to the client, my log file was showing a return of 200. I've got
PerlSendHeader enabled. So, I was trying to find a way to get the access
log to show the 304 response instead of 200.
The solution was to exit with Apache::exit( HTTP_NOT_MODIFIED ) as
suggested by Darren Chamberlain.
To make this run where mod_perl is not installed, I had to do some ugly and
clumsy coding (which I welcome a better solution). Remember, I'm trying to
get this code to work under mod_cgi or mod_perl.
BEGIN {
eval "use Apache";
eval "use Apache::Constants qw/OK HTTP_NOT_MODIFIED/;";
if( $@ ) {
eval "sub OK { 0; }"; die "$@" if $@;
eval "sub HTTP_NOT_MODIFIED { 0; }"; die "$@" if $@;
}
}
Then in my 304 generating routine I can call exit_program(1) when I want to
generate the 304 in the access log file.
sub exit_program {
my $return_code = ( shift ) ? HTTP_NOT_MODIFIED : OK;
( ($ENV{GATEWAY_INTERFACE} &&
$ENV{GATEWAY_INTERFACE} =~ /^CGI-Perl/ )
|| $ENV{MOD_PERL} )
? Apache::exit( $return_code )
: exit;
}
Now this gets the 304 in my access log file, but it also has two side
effects that I'm trying to understand:
1) When calling Apache::exit( HTTP_NOT_MODIFIED ) Apache is creating double
headers. I know I read about this some place, but I can't seem to find it
now.
Here's what's being sent:
HTTP/1.1 304 (Not Modified) Not Modified
Connection: close
Date: Thu, 18 Nov 1999 18:35:29 GMT
Server: Apache/1.3.9 (Unix) mod_perl/1.21
Content-Type: text/plain
Client-Date: Thu, 18 Nov 1999 18:35:15 GMT
Client-Peer: 169.229.32.30:3029
HTTP/1.1 304 Not Modified
Date: Thu, 18 Nov 1999 18:35:29 GMT
Server: Apache/1.3.9 (Unix) mod_perl/1.21
Connection: close
I get the headers I'd expect (not duplicated) if I call Apache::exit( OK ),
even when sending Status: 304 Not Modified.
2) Now when exiting via Apache::exit( HTTP_NOT_MODIFIED ) I get this in my
server error log:
[Thu Nov 18 10:35:29 1999] [error] 304
I wasn't expecting to see that, I guess. Requesting an image, for example,
that returns a 304 error doesn't place that message in the log file.
Thanks,
Bill Moseley
mailto:[EMAIL PROTECTED]