如何设置 mod_deflate 首选压缩方法为 deflate

发布于 2024-09-18 02:09:52 字数 302 浏览 11 评论 0原文

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

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

如果这是不可能的...为什么开发人员在无法收缩时将模块命名为 mod_deflate 呢?另外,对于我来说,提交错误报告以在未来版本中修复此问题的最佳方法(如果有)是什么?

mod_deflate always sends gzip data when the request header Accept-Encoding is gip, deflate.

How can I tell mod_deflate to prefer to send deflate (NOT zlib) instead of gzip?

If this isn't possible...why would the develpers name the module mod_deflate when it can't deflate. Also, what is the best way, if any, for me to submit a bug report to have this fixed in future releases?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜妞爱困 2024-09-25 02:09:52

查看 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}
};

After looking at the source code for mod_deflate I have come to the conclusion that it is impossible to send anything other than gzip.

Now, I'm not a c programmer and I don't think I'll be able to commit any patches myself...but from the source I can see that there are a few things that need to be fixed (warning, I've never written any c...so this is all probably terribly wrong)

/* 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}
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文