【问题标题】:How to set mod_deflate preferred compression method to deflate如何设置 mod_deflate 首选压缩方法放气
【发布时间】:2023-03-21 10:50:01
【问题描述】:

当请求头 Accept-Encodinggip, deflate 时,mod_deflate 总是发送 gzip 数据。

我如何告诉 mod_deflate 更喜欢发送 deflate(不是 zlib)而不是 gzip

如果这是不可能的...为什么开发人员在模块不能放气时将其命名为 mod_deflate。另外,如果有的话,我提交错误报告以在将来的版本中修复此问题的最佳方式是什么?

【问题讨论】:

    标签: apache compression gzip deflate mod-deflate


    【解决方案1】:

    看了source code for mod_deflate我得出的结论是,除了gzip之外不可能发送任何东西。

    现在,我不是c 程序员,我认为我自己无法提交任何补丁...但是从源代码中我可以看到需要做一些事情已修复(警告,我从未写过任何 c...所以这可能是非常错误的)

    /* add this method */
    static const char *deflate_set_preferred_method(cmd_parms *cmd, void *dummy,
                                    const char *arg1)
    {
        deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
                                                    &deflate_module);
    
        if (arg2 != NULL && (!strcasecmp(arg1, "deflate") || !strcasecmp(arg1, "gzip") || !strcasecmp(arg1, "zlib") ) ) {
            c->preferred_method = apr_pstrdup(cmd->pool, arg1);
        }
        else {
            return apr_psprintf(cmd->pool, "Unknown preferred method type %s", arg1);
        }
    
        return NULL;
    }
    
    /* update some code to define "preferred_method" */
    
    
    /* 
       Update all code that references the string "gzip" to take 
       into account "deflate", and "zlib" as well.
    
       This is the part I really have no clue how to do.
       lines: 539, 604, 607, 616, and 624 should be updates
    
       line 624 could read something like this: */
    
    if( !strcasecmp(preferred_method,"gzip") ){
        /* 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);
    }
    else if( !strcasecmp(preferred_method, "zlib") ){
       /* do something to add the zlib headers here */
    }
    
    /* update this method */
    static const command_rec deflate_filter_cmds[] = {
        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)"),
        AP_INIT_TAKE1("DeflateBufferSize", deflate_set_buffer_size, NULL, RSRC_CONF,
                      "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)"),
        AP_INIT_TAKE1("DeflatePreferredMethod", deflate_set_preferred_method, NULL, RSRC_CONF,
                      "Set the Preferred Compression Method: deflate, gzip, or zlib (not-recommended)"),
        {NULL}
    };
    

    【讨论】: