Hi Thomas,

I've created a patch for the file at 
https://github.com/OutOfOrder/mod_log_sql/blob/1.100/functions.h

This is the patch:


diff --git a/functions.h b/functions.h
index b35634a..dcbf710 100644
--- a/functions.h
+++ b/functions.h
@@ -90,10 +90,16 @@ static const char *extract_request_query(request_rec *r, 
char *a)
 
 static const char *extract_status(request_rec *r, char *a)
 {
-       if (r->status <= 0) {
+       int status = r->status;
+       if (r->next){
+       request_rec *r2 = r->next;
+       status = r2->status;
+       }
+
+       if (status <= 0) {
        return "-";
        } else {
-       return apr_psprintf(r->pool, "%d", r->status);
+       return apr_psprintf(r->pool, "%d", status);
        }
 }
 
I'm not sure if this is the final solution for every use case, but it fixes the 
issues at my REST API. Maybe someone else needs the `if` to be a `while` 
statement.

Best,
Luc van Donkersgoed

> On 22 sep. 2015, at 13:31, Thomas Goirand <z...@debian.org> wrote:
> 
>> On 09/21/2015 09:38 PM, Luc van Donkersgoed wrote:
>> I ran into this thread because I wanted to use mod_log_sql with
>> mod_rewrite. I ran into the exact problem described in this thread. 
>> 
>> I managed to fix it by patching libapache2-mod-log-sql and compiling it
>> myself. 
>> 
>> The adjustment is in
>> functions.h: 
>> https://github.com/OutOfOrder/mod_log_sql/blob/1.100/functions.h#L91-L98
>> 
>> In this function, request_rec->status is used, but as described
>> in http://httpd.apache.org/docs/2.2/developer/API.html#log_handlers:
>> 
>>> When a request has internally redirected, there is the question of what
>> to log. Apache handles this by bundling the entire chain of redirects
>> into a list of request_rec structures which are threaded through the
>> r->prev and r->next pointers. The request_rec which is passed to the
>> logging handlers in such cases is the one which was originally built for
>> the initial request from the client; note that the bytes_sent field will
>> only be correct in the last request in the chain (the one for which a
>> response was actually sent).
>> 
>> This is the root cause of the problem. By checking if request_rec is not
>> null, and if that's the case, using the next request's status code, the
>> correct status codes are stored in the database. This solution works for
>> requests through mod_rewrite as well as requests which are not rewritten.
>> 
>> Best,
>> Luc van Donkersgoed
> 
> Hi Luc,
> 
> Would you be able to provide a patch for this?
> 
> Cheers,
> 
> Thomas Goirand (zigo)
> 

Reply via email to