httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ruediger Pluem <rpl...@apache.org>
Subject [Patch]: Do not compress bodies of header only requests in mod_deflate
Date Mon, 17 Jul 2006 17:28:38 GMT
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

Mime
View raw message