This bubbled up on some discussion with statistic freaks:

The attached patch allows the user to log the accurate filter input and 
output byte count, instead of only the rounded compression ratio.
The DeflateFilterNote directive will be extended as follows:

DeflateFilterNote [type] name

type can be one of "input", "output" or "ratio". "ratio" is assumed if the 
type is omitted (backwards compatible).
Example:

DeflateFilterNote input deflate-in
DeflateFilterNote output deflate-out

LogFormat '%t "%r" %{deflate-in}n/%{deflate-out}n' deflate

nd
-- 
Treat your password like your toothbrush. Don't let anybody else
use it, and get a new one every six months.  -- Clifford Stoll

                                    (found in ssl_engine_pphrase.c)

Index: mod_deflate.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/filters/mod_deflate.c,v
retrieving revision 1.26
diff -u -r1.26 mod_deflate.c
--- mod_deflate.c       14 Nov 2002 19:22:26 -0000      1.26
+++ mod_deflate.c       22 Nov 2002 01:53:01 -0000
@@ -129,7 +129,9 @@
     int windowSize;
     int memlevel;
     apr_size_t bufferSize;
-    char *noteName;
+    char *noteRatioName;
+    char *noteInputName;
+    char *noteOutputName;
 } deflate_filter_config;
 
 /* windowsize is negative to suppress Zlib header */
@@ -202,11 +204,26 @@
     return NULL;
 }
 static const char *deflate_set_note(cmd_parms *cmd, void *dummy,
-                                    const char *arg)
+                                    const char *arg1, const char *arg2)
 {
     deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
                                                     &deflate_module);
-    c->noteName = apr_pstrdup(cmd->pool, arg);
+    
+    if (arg2 == NULL) {
+        c->noteRatioName = apr_pstrdup(cmd->pool, arg1);
+    }
+    else if (!strcasecmp(arg1, "ratio")) {
+        c->noteRatioName = apr_pstrdup(cmd->pool, arg2);
+    }
+    else if (!strcasecmp(arg1, "input")) {
+        c->noteInputName = apr_pstrdup(cmd->pool, arg2);
+    }
+    else if (!strcasecmp(arg1, "output")) {
+        c->noteOutputName = apr_pstrdup(cmd->pool, arg2);
+    }
+    else {
+        return apr_psprintf(cmd->pool, "Unknown note type %s", arg1);
+    }
 
     return NULL;
 }
@@ -239,6 +256,11 @@
     apr_bucket_brigade *bb, *proc_bb;
 } deflate_ctx;
 
+#define LeaveNote(type, value) \
+    if (c->note##type##Name) \
+        apr_table_setn(r->notes, c->note##type##Name, \
+                       (ctx->stream.total_in > 0) ? (value) : "-")
+
 static apr_status_t deflate_out_filter(ap_filter_t *f,
                                        apr_bucket_brigade *bb)
 {
@@ -433,19 +455,11 @@
                           "Zlib: Compressed %ld to %ld : URL %s",
                           ctx->stream.total_in, ctx->stream.total_out, r->uri);
 
-            if (c->noteName) {
-                if (ctx->stream.total_in > 0) {
-                    int total;
-
-                    total = ctx->stream.total_out * 100 / ctx->stream.total_in;
-
-                    apr_table_setn(r->notes, c->noteName,
-                                   apr_itoa(r->pool, total));
-                }
-                else {
-                    apr_table_setn(r->notes, c->noteName, "-");
-                }
-            }
+            LeaveNote(Input, apr_off_t_toa(r->pool, ctx->stream.total_in));
+            LeaveNote(Output, apr_off_t_toa(r->pool, ctx->stream.total_out));
+            LeaveNote(Ratio, apr_itoa(r->pool, (int)
+                                      (ctx->stream.total_out * 100 /
+                                      ctx->stream.total_in)));
 
             deflateEnd(&ctx->stream);
 
@@ -775,7 +789,7 @@
 }
 
 static const command_rec deflate_filter_cmds[] = {
-    AP_INIT_TAKE1("DeflateFilterNote", deflate_set_note, NULL, RSRC_CONF,
+    AP_INIT_TAKE12("DeflateFilterNote", deflate_set_note, NULL, RSRC_CONF,
                   "Set a note to report on compression ratio"),
     AP_INIT_TAKE1("DeflateWindowSize", deflate_set_window_size, NULL,
                   RSRC_CONF, "Set the Deflate window size (1-15)"),

Reply via email to