[mp2] Problems with $r->bytes_sent and $r->status in log handler

[prev] [thread] [next] [Date index for 2005/04/18]

From: Markus Wichitill
Subject: [mp2] Problems with $r->bytes_sent and $r->status in log handler
Date: 20:49 on 18 Apr 2005
Hi,

I have a log handler that is supposed to log whether certain 
HTTP-authenticated customers were able to completely download their digital 
deliveries. The mod_perl 1.x version works just fine.

Now under SuSE Linux 9.2/Apache 2.0.53/mod_perl 2.0 RC4, $r->bytes_sent 
seems to always contain the full size of the file resource, not the bytes 
really sent to the client on an interrupted download. Unless it's a byte 
range request, in which case it contains the full size of the range. Does 
anybody know whether this is perhaps expected behaviour under Apache2, maybe 
a result of its fancy filter architecture? Could it be a mod_perl bug,  or 
is mod_perl only a thin wrapper around the C structures in this case, and 
therefore most likely innocent?

If I add mod_ssl to the mix, $r->status acts wonky, too. When it should be 
200 (and $r->status_line contains the correct "200 OK"), it's the apparently 
nonsensical 104. When it should be 206 for a byte range request (and 
$r->status_line contains the correct "206 Partial Content"), it's 200. Other 
people with the same user agent managed to produce other combinations, 
though. Any ideas?

Somewhat simplified code (for mod_perl 2.0 RC4):

package MyClient::AuthLog2;
use strict;
use Apache::Const -compile => qw(OK);
use Apache::Util ();
use APR::Finfo ();

sub handler
{
   my $r = shift();

   my $user = $r->user;
   if ($user) {
     my $date = Apache::Util::ht_time(
       $r->pool, $r->request_time, "%Y-%m-%d %H:%M", 0);
     my $remote = $r->connection->get_remote_host();
     my $uri = $r->uri;
     my $status = $r->status;
     my $status_line = $r->status_line;
     my $bytes_file = $r->finfo->size;
     my $bytes_sent = $r->bytes_sent;
     my $result = "";

     if ($status == 200 && $bytes_sent == $bytes_file) {
       $result = 'complete'
     }
     elsif ($status == 200 && $bytes_sent != $bytes_file) {
       $result = 'incomplete'
     }
     elsif ($status == 206) {
       $result = 'partial'
     }

     open LOG, ">>/var/log/apache2/auth_log" or warn "Can't open auth log";
     print LOG "$date|$remote|$user|$uri|",
       "$status|$status_line|$bytes_file|$bytes_sent|$result\n";
     close LOG;
   }

   return Apache::OK;
}

[mp2] Problems with $r->bytes_sent and $r->status in log handler
Markus Wichitill 20:49 on 18 Apr 2005

Generated at 09:30 on 27 Apr 2005 by mariachi v0.52