personally I think GET & HEAD processing should be identical until the very last moment. this avoids bugs creeping in which process the body for some reason and add a header after mod_deflate is run
(I can't think of any which do this BTW)

are you seeing a problem somewhere Ruediger?

regards
Ian
On 18/07/2006, at 3:28 AM, Ruediger Pluem wrote:

The following patch avoids that the deflate output filter wastes cycles in compressing the body of a header only request that gets thrown away by http
header filter afterwards anyway.
OTH a HEAD and a GET request differ regarding regarding the T-E and C-L headers (everything else is the same). So I am not sure if this patch breaks RFC2616.

Comments?

Index: modules/filters/mod_deflate.c
===================================================================
--- modules/filters/mod_deflate.c       (Revision 422739)
+++ modules/filters/mod_deflate.c       (Arbeitskopie)
@@ -397,8 +397,6 @@

         /* We're cool with filtering this. */
         ctx = f->ctx = apr_pcalloc(r->pool, sizeof(*ctx));
-        ctx->bb = apr_brigade_create(r->pool, f->c->bucket_alloc);
-        ctx->buffer = apr_palloc(r->pool, c->bufferSize);

zRC = deflateInit2(&ctx->stream, c->compressionlevel, Z_DEFLATED,
                            c->windowSize, c->memlevel,
@@ -418,11 +416,6 @@
             return ap_pass_brigade(f->next, bb);
         }

-        /* add immortal gzip header */
- e = apr_bucket_immortal_create(gzip_header, sizeof gzip_header,
-                                       f->c->bucket_alloc);
-        APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
-
/* If the entire Content-Encoding is "identity", we can replace it. */
         if (!encoding || !strcasecmp(encoding, "identity")) {
apr_table_setn(r->headers_out, "Content-Encoding", "gzip");
@@ -432,6 +425,24 @@
         }
         apr_table_unset(r->headers_out, "Content-Length");

+        /*
+ * Do not waste cycles on compressing bodys of header only requests as
+         * the body data is dumped later anyway.
+         */
+        if (r->header_only) {
+            deflateEnd(&ctx->stream);
+            ap_remove_output_filter(f);
+
+        }
+
+        ctx->bb = apr_brigade_create(r->pool, f->c->bucket_alloc);
+        ctx->buffer = apr_palloc(r->pool, c->bufferSize);
+
+        /* add immortal gzip header */
+ e = apr_bucket_immortal_create(gzip_header, sizeof gzip_header,
+                                       f->c->bucket_alloc);
+        APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
+
         /* initialize deflate output buffer */
         ctx->stream.next_out = ctx->buffer;
         ctx->stream.avail_out = c->bufferSize;
          return ap_pass_brigade(f->next, bb);



Regards

RĂ¼diger
Index: modules/filters/mod_deflate.c
===================================================================
--- modules/filters/mod_deflate.c       (Revision 422739)
+++ modules/filters/mod_deflate.c       (Arbeitskopie)
@@ -397,8 +397,6 @@

         /* We're cool with filtering this. */
         ctx = f->ctx = apr_pcalloc(r->pool, sizeof(*ctx));
-        ctx->bb = apr_brigade_create(r->pool, f->c->bucket_alloc);
-        ctx->buffer = apr_palloc(r->pool, c->bufferSize);

zRC = deflateInit2(&ctx->stream, c->compressionlevel, Z_DEFLATED,
                            c->windowSize, c->memlevel,
@@ -418,11 +416,6 @@
             return ap_pass_brigade(f->next, bb);
         }

-        /* add immortal gzip header */
- e = apr_bucket_immortal_create(gzip_header, sizeof gzip_header,
-                                       f->c->bucket_alloc);
-        APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
-
/* If the entire Content-Encoding is "identity", we can replace it. */
         if (!encoding || !strcasecmp(encoding, "identity")) {
apr_table_setn(r->headers_out, "Content-Encoding", "gzip");
@@ -432,6 +425,24 @@
         }
         apr_table_unset(r->headers_out, "Content-Length");

+        /*
+ * Do not waste cycles on compressing bodys of header only requests as
+         * the body data is dumped later anyway.
+         */
+        if (r->header_only) {
+            deflateEnd(&ctx->stream);
+            ap_remove_output_filter(f);
+            return ap_pass_brigade(f->next, bb);
+        }
+
+        ctx->bb = apr_brigade_create(r->pool, f->c->bucket_alloc);
+        ctx->buffer = apr_palloc(r->pool, c->bufferSize);
+
+        /* add immortal gzip header */
+ e = apr_bucket_immortal_create(gzip_header, sizeof gzip_header,
+                                       f->c->bucket_alloc);
+        APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
+
         /* initialize deflate output buffer */
         ctx->stream.next_out = ctx->buffer;
         ctx->stream.avail_out = c->bufferSize;

Reply via email to