【问题标题】:Set custom header to apache response within a module将自定义标头设置为模块内的 apache 响应
【发布时间】:2016-04-27 14:23:58
【问题描述】:

我正在创建一个使用 AES 加密数据的 apache 模块。 我的最终目标是为每个请求使用不同的 AES 密钥,生成一个 16 字节的新密钥,用于 AES 加密文件并将密钥(使用 RSA 加密)作为自定义标头发送

问题是我找不到任何文档来以编程方式设置自定义标题。

我期待类似ap_set_handler("HeaderName","content")

我只发现这个文件使用了这样的功能: http://opensource.apple.com/source/apache/apache-643/apache/src/modules/proxy/proxy_ftp.c

问题是在我的源代码中包含它会给我一个implicit declaration of function 'ap_set_header' 错误,即使我包含了该文件的相同 .h 文件。

我很确定它可以完成,但我真的不知道在哪里搜索

【问题讨论】:

    标签: apache apache-modules


    【解决方案1】:

    经过 2 天的努力,我找到了查看 mod_headers 源代码的方法(否则几乎不可能在不知道的情况下在文档中找到它)

    实际上,Apache 为您提供的request_rec *r 实例在处理程序中有一个非常有用的r->headers_outfield。

    您可以在此处找到“文档”:https://ci.apache.org/projects/httpd/trunk/doxygen/structrequest__rec.html#afecc56ea8fb015aa52477dba471a6612

    r->headers_outapr_table_t,因此您可以使用适当的函数对其进行修改:

    /* Add header at the end of table */
    ap_table_mergen(r->headers_out, "NameField", "value");
    /* Overwrite value of "NameField" header or add it (if not existing) */
    ap_table_setn(r->headers_out, "NameField", "value");
    /* Unset header */
    ap_table_unset(r->headers_out, "NameField");
    

    【讨论】:

      猜你喜欢
      • 2011-08-21
      • 2020-02-09
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      • 2022-12-15
      • 1970-01-01
      • 2012-06-12
      • 2016-12-21
      相关资源
      最近更新 更多