Some questions about mod_deflate : 1) Why this module is not enabled by default built ? compression should be on to meet HTTP recommandations ?
2) What about a more advanced system ? Currently : SetEnv gzip-only-text/html 1 -> make mod_deflate compress only text/html. Extension : SetEnv gzip-mime-xxxx/yyyy allow -> make mod_deflate compress content matching xxxx/yyyy. SetEnv gzip-mime-xxxx/yyyy deny -> make mod_deflate don't compress content matching xxxx/yyyy. SetEnv gzip-file-jsp allow -> make mod_deflate compress content caming from jsp SetEnv gzip-file-js deny -> make mod_deflate don't compress content caming for javascript <Directory "/your-server-root/manual"> SetEnv gzip-mime-text/html allow SetEnv gzip-mime-text/xml allow SetEnv gzip-mime-text/plain allow SetEnv gzip-mime-default deny SetEnv gzip-file-jsp allow SetEnv gzip-file-js deny SetEnv gzip-file-default deny SetOutputFilter DEFLATE </Directory> Attached is a patch ... Thanks for your feedback
--- modules/filters/mod_deflate.c.orig Fri Aug 30 18:31:17 2002 +++ modules/filters/mod_deflate.c Fri Nov 8 17:43:00 2002 @@ -239,6 +239,39 @@ apr_bucket_brigade *bb, *proc_bb; } deflate_ctx; +static char * get_file_ext(request_rec *r) +{ + char * ext; + int i, len; + + /* no filename, bye */ + if (! r->filename) + return (NULL); + + len = strlen(r->filename); + + /* we shoud have ad minim x.y */ + if (len < 3) + return (NULL); + + /* skip end of string */ + len--; + ext = r->filename + len; + + /* filename 'xxx.' is invalid */ + if (*ext == '.') + return (NULL); + + while (len) { + if (*ext == '.') + return (apr_pstrdup(r->pool, ext + 1)); + ext--; + len--; + } + + return (NULL); +} + static apr_status_t deflate_out_filter(ap_filter_t *f, apr_bucket_brigade *bb) { @@ -258,7 +291,8 @@ if (!ctx) { char *buf, *token; const char *encoding, *accepts; - + int reject = 0; + /* only work on main request/no subrequests */ if (r->main) { ap_remove_output_filter(f); @@ -287,6 +321,75 @@ } } + /* Check content-type and determine if we should do the + * compression, so set gzip-mime-xxxx/yyyy allow + * to process or gzip-mime-xxxx/yyyy deny to reject + * set gzip-mime-default allow/deny to set default mode + * You could use browsermatch to change behaviour by browser + */ + if (r->content_type != NULL) { + const char * ismime = apr_pstrcat(r->pool, + "gzip-mime-", + r->content_type, + NULL); + + const char *env_value = apr_table_get(r->subprocess_env, + ismime); + /* If no gzip-mime-xxxx/yyyy specified check default flag */ + + if (! env_value) { + env_value = apr_table_get(r->subprocess_env, + "gzip-mime-default"); + + /* default not specified or don't set allow, reject it */ + + if (! env_value || strcmp(env_value,"allow")) + reject = 1; + } + else { + if (strcmp(env_value,"allow")) + reject = 1; + } + + } + else { + /* Check for gzip-file-xxxx by extension to see if compression + * should be conducted + * so set gzip-file-xxx allow or gzip-file-xxx deny to reject + * set gzip-file-default allow/deny to set default mode + * You could use browsermatch to change behaviour by browser + */ + const char * fileext = get_file_ext(r); + + /* no valid file extension found, reject it */ + if (! fileext) + reject = 1; + else { + const char * isfile = apr_pstrcat(r->pool, + "gzip-file-", + fileext, + NULL); + + const char *env_value = apr_table_get(r->subprocess_env, + isfile); + /* If no gzip-file-xxxx/yyyy specified check default flag */ + + if (! env_value) { + env_value = apr_table_get(r->subprocess_env, + "gzip-file-default"); + + /* default not specified or don't set allow, reject it */ + + if (! env_value || strcmp(env_value,"allow")) + reject = 1; + } + else { + if (strcmp(env_value,"allow")) + reject = 1; + } + } + } + + /* reject asked, don't go farther and pass to next one in chain */ + if (reject) { + ap_remove_output_filter(f); + return ap_pass_brigade(f->next, bb); + } + /* Let's see what our current Content-Encoding is. * If gzip is present, don't gzip again. (We could, but let's not.) */