httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i...@apache.org
Subject cvs commit: httpd-2.0/modules/filters mod_deflate.c
Date Tue, 11 Mar 2003 18:04:37 GMT
ianh        2003/03/11 10:04:37

  Modified:    .        Tag: APACHE_2_0_BRANCH CHANGES STATUS
               docs/manual/mod Tag: APACHE_2_0_BRANCH mod_deflate.xml
               modules/filters Tag: APACHE_2_0_BRANCH mod_deflate.c
  Log:
  Backport from 2.1 tree. Only difference is that the name of the directive was changed to
  DeflateCompressionLevel
  
    *) you can now specify the compression level for mod_deflate.
       [Ian Holsman, Stephen Pierzchala <stephen@pierzchala.com>,
       Michael Schroepl <Michael.Schroepl@telekurs.de>]
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.988.2.59 +4 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.988.2.58
  retrieving revision 1.988.2.59
  diff -u -r1.988.2.58 -r1.988.2.59
  --- CHANGES	11 Mar 2003 06:40:40 -0000	1.988.2.58
  +++ CHANGES	11 Mar 2003 18:04:30 -0000	1.988.2.59
  @@ -1,5 +1,9 @@
   Changes with Apache 2.0.45
   
  +  *) you can now specify the compression level for mod_deflate. 
  +     [Ian Holsman, Stephen Pierzchala <stephen@pierzchala.com>, 
  +     Michael Schroepl <Michael.Schroepl@telekurs.de>]
  +
     *) Allow SSLMutex to select/use the full range of APR locking
        mechanisms available to it. Also, fix the bug that SSLMutex uses
        APR_LOCK_DEFAULT no matter what.  PR 8122  [Jim Jagielski,
  
  
  
  1.751.2.170 +4 -8      httpd-2.0/STATUS
  
  Index: STATUS
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/STATUS,v
  retrieving revision 1.751.2.169
  retrieving revision 1.751.2.170
  diff -u -r1.751.2.169 -r1.751.2.170
  --- STATUS	11 Mar 2003 07:07:51 -0000	1.751.2.169
  +++ STATUS	11 Mar 2003 18:04:33 -0000	1.751.2.170
  @@ -166,12 +166,6 @@
         modules/generators/mod_autoindex.c: r1.119
         +1: nd, wrowe, trawick
   
  -    * New Directive for mod_deflate (compressionlevel), and change to default
  -      compression level
  -      mod_deflate.c 1.31
  -      +1: ianh, wrowe, trawick
  -       0: nd (err, shouldn't it be DeflateCompressionLevel?)
  -
       * Forward port: Escape special characters (especially control
         characters) in mod_log_config to make a clear distinction between
         client-supplied strings (with special characters) and server-side
  @@ -182,12 +176,14 @@
         server/gen_test_char.c: r1.16
         server/util.c: r1.138
         +1: nd
  +      +0: mod_log_config.c has another change which requires mod_log_config.h
  +         and a possible mmn bump
   
       * mod_deflate: Check also err_headers_out for an already set
         Content-Encoding: gzip header. This prevents gzip compressed content
         from a CGI script from being compressed once more. PR 17797.
         modules/filters/mod_deflate.c: r1.32
  -      +1: nd
  +      +1: nd, ianh
   
       * mod_negotiation: parse quality values independent from
         the current locale and level values as integers. PR 17564.
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.12.2.2  +51 -2     httpd-2.0/docs/manual/mod/mod_deflate.xml
  
  Index: mod_deflate.xml
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/docs/manual/mod/mod_deflate.xml,v
  retrieving revision 1.12.2.1
  retrieving revision 1.12.2.2
  diff -u -r1.12.2.1 -r1.12.2.2
  --- mod_deflate.xml	22 Dec 2002 15:29:51 -0000	1.12.2.1
  +++ mod_deflate.xml	11 Mar 2003 18:04:35 -0000	1.12.2.2
  @@ -16,7 +16,7 @@
       your server to be compressed before being sent to the client over
       the network.</p>
   </summary>
  -<seealso><a href="../filter.html">The filter documentation</a></seealso>
  +<seealso><a href="../filter.html">Filters</a></seealso>
   
   <section id="recommended"><title>Recommended Configuration</title>
       <p>This is a sample configuration for the impatient. But please take
  @@ -190,9 +190,10 @@
   <directivesynopsis>
   <name>DeflateFilterNote</name>
   <description>Places the compression ratio in a note for logging</description>
  -<syntax>DeflateFilterNote <var>notename</var></syntax>
  +<syntax>DeflateFilterNote [<var>type</var>] <var>notename</var></syntax>
   <contextlist><context>server config</context><context>virtual host</context>
   </contextlist>
  +<compatibility><var>type</var> is available since Apache 2.0.45</compatibility>
   
   <usage>
       <p>The <directive>DeflateFilterNote</directive> directive
  @@ -208,6 +209,34 @@
         LogFormat '"%r" %b (%{ratio}n) "%{User-agent}i"' deflate<br />
         CustomLog logs/deflate_log deflate
       </example>
  +
  +    <p>If you want to extract more accurate values from your logs, you
  +    can use the <var>type</var> argument to specify the type of data
  +    left as note for logging. <var>type</var> can be one of:</p>
  +
  +    <dl>
  +      <dt><code>Input</code></dt>
  +      <dd>Store the byte count of the filter's input stream in the note.</dd>
  +
  +      <dt><code>Output</code></dt>
  +      <dd>Store the byte count of the filter's output stream in the note.</dd>
  +
  +      <dt><code>Ratio</code></dt>
  +      <dd>Store the compression ratio (<code>output/input * 100</code>)
  +      in the note. This is the default, if the <var>type</var> argument
  +      is omitted.</dd>
  +    </dl>
  +
  +    <p>Thus you may log it this way:</p>
  +
  +    <example><title>Accurate Logging</title>
  +      DeflateFilterNote Input instream<br />
  +      DeflateFilterNote Output outstream<br />
  +      DeflateFilterNote Ratio ratio<br />
  +      <br />
  +      LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate<br />
  +      CustomLog logs/deflate_log deflate
  +    </example>
   </usage>
   <seealso><module>mod_log_config</module></seealso>
   </directivesynopsis>
  @@ -243,6 +272,7 @@
   </directivesynopsis>
   
   <directivesynopsis>
  +
   <name>DeflateMemLevel</name>
   <description>How much memory should be used by zlib for compression</description>
   <syntax>DeflateMemLevel <var>value</var></syntax>
  @@ -256,6 +286,25 @@
       (a value between 1 and 9).</p>
   </usage>
   </directivesynopsis>
  +
  +<directivesynopsis>
  +<name>DeflateCompressionLevel</name>
  +<description>How much compression do we apply to the output</description>
  +<syntax>DeflateCompressionLevel<var>value</var></syntax>
  +<default>Zlib's default</default>
  +<contextlist><context>server config</context><context>virtual host</context>
  +</contextlist>
  +<compatibility>This directive is available since Apache 2.0.45</compatibility>
  +
  +<usage>
  +    <p>The <directive>DeflateCompressionLevel</directive> directive specifies
  +        what level of compression should be used, the higher the value, 
  +        the better the compression, but the more CPU time is required to
  +        achieve this.</p>
  +    <p>The value must between 1 (less compression) and 9 (more compression).</p>
  +</usage>
  +</directivesynopsis>
  +
   
   </modulesynopsis>
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.26.2.3  +69 -17    httpd-2.0/modules/filters/mod_deflate.c
  
  Index: mod_deflate.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/filters/mod_deflate.c,v
  retrieving revision 1.26.2.2
  retrieving revision 1.26.2.3
  diff -u -r1.26.2.2 -r1.26.2.3
  --- mod_deflate.c	27 Feb 2003 04:24:38 -0000	1.26.2.2
  +++ mod_deflate.c	11 Mar 2003 18:04:36 -0000	1.26.2.3
  @@ -128,11 +128,15 @@
   {
       int windowSize;
       int memlevel;
  +    int compressionlevel;
       apr_size_t bufferSize;
  -    char *noteName;
  +    char *note_ratio_name;
  +    char *note_input_name;
  +    char *note_output_name;
   } deflate_filter_config;
   
   /* windowsize is negative to suppress Zlib header */
  +#define DEFAULT_COMPRESSION Z_DEFAULT_COMPRESSION
   #define DEFAULT_WINDOWSIZE -15
   #define DEFAULT_MEMLEVEL 9
   #define DEFAULT_BUFFERSIZE 8096
  @@ -165,6 +169,7 @@
       c->memlevel   = DEFAULT_MEMLEVEL;
       c->windowSize = DEFAULT_WINDOWSIZE;
       c->bufferSize = DEFAULT_BUFFERSIZE;
  +    c->compressionlevel = DEFAULT_COMPRESSION;
   
       return c;
   }
  @@ -202,11 +207,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->note_ratio_name = apr_pstrdup(cmd->pool, arg1);
  +    }
  +    else if (!strcasecmp(arg1, "ratio")) {
  +        c->note_ratio_name = apr_pstrdup(cmd->pool, arg2);
  +    }
  +    else if (!strcasecmp(arg1, "input")) {
  +        c->note_input_name = apr_pstrdup(cmd->pool, arg2);
  +    }
  +    else if (!strcasecmp(arg1, "output")) {
  +        c->note_output_name = apr_pstrdup(cmd->pool, arg2);
  +    }
  +    else {
  +        return apr_psprintf(cmd->pool, "Unknown note type %s", arg1);
  +    }
   
       return NULL;
   }
  @@ -228,6 +248,23 @@
       return NULL;
   }
   
  +static const char *deflate_set_compressionlevel(cmd_parms *cmd, void *dummy,
  +                                        const char *arg)
  +{
  +    deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
  +                                                    &deflate_module);
  +    int i;
  +
  +    i = atoi(arg);
  +
  +    if (i < 1 || i > 9)
  +        return "Compression Level must be between 1 and 9";
  +
  +    c->compressionlevel = i;
  +
  +    return NULL;
  +}
  +
   /* magic header */
   static char deflate_magic[2] = { '\037', '\213' };
   
  @@ -337,7 +374,7 @@
           ctx->bb = apr_brigade_create(r->pool, f->c->bucket_alloc);
           ctx->buffer = apr_palloc(r->pool, c->bufferSize);
   
  -        zRC = deflateInit2(&ctx->stream, Z_BEST_SPEED, Z_DEFLATED,
  +        zRC = deflateInit2(&ctx->stream, c->compressionlevel, Z_DEFLATED,
                              c->windowSize, c->memlevel,
                              Z_DEFAULT_STRATEGY);
   
  @@ -433,18 +470,31 @@
                             "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;
  +            /* leave notes for logging */
  +            if (c->note_input_name) {
  +                apr_table_setn(r->notes, c->note_input_name,
  +                               (ctx->stream.total_in > 0)
  +                                ? apr_off_t_toa(r->pool,
  +                                                ctx->stream.total_in)
  +                                : "-");
  +            }
   
  -                    total = ctx->stream.total_out * 100 / ctx->stream.total_in;
  +            if (c->note_output_name) {
  +                apr_table_setn(r->notes, c->note_output_name,
  +                               (ctx->stream.total_in > 0)
  +                                ? apr_off_t_toa(r->pool,
  +                                                ctx->stream.total_out)
  +                                : "-");
  +            }
   
  -                    apr_table_setn(r->notes, c->noteName,
  -                                   apr_itoa(r->pool, total));
  -                }
  -                else {
  -                    apr_table_setn(r->notes, c->noteName, "-");
  -                }
  +            if (c->note_ratio_name) {
  +                apr_table_setn(r->notes, c->note_ratio_name,
  +                               (ctx->stream.total_in > 0)
  +                                ? apr_itoa(r->pool,
  +                                           (int)(ctx->stream.total_out
  +                                                 * 100
  +                                                 / ctx->stream.total_in))
  +                                : "-");
               }
   
               deflateEnd(&ctx->stream);
  @@ -580,7 +630,7 @@
           if (rv != APR_SUCCESS) {
               return rv;
           }
  -      
  +
           len = 10; 
           rv = apr_brigade_flatten(ctx->bb, deflate_hdr, &len); 
           if (rv != APR_SUCCESS) {
  @@ -733,7 +783,7 @@
                   }
   
                   inflateEnd(&ctx->stream);
  -    
  +
                   eos = apr_bucket_eos_create(f->c->bucket_alloc);
                   APR_BRIGADE_INSERT_TAIL(ctx->proc_bb, eos); 
                   break;
  @@ -784,7 +834,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)"),
  @@ -792,6 +842,8 @@
                     "Set the Deflate Buffer Size"),
       AP_INIT_TAKE1("DeflateMemLevel", deflate_set_memlevel, NULL, RSRC_CONF,
                     "Set the Deflate Memory Level (1-9)"),
  +    AP_INIT_TAKE1("DeflateCompressionLevel", deflate_set_compressionlevel, NULL, RSRC_CONF,
  +                  "Set the Deflate Compression Level (1-9)"),
       {NULL}
   };
   
  
  
  

Mime
View raw message