将自定义 header 设置为模块内的 apache 响应

Set custom header to apache response within a module

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

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

我期待 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 文件。

我很确定可以做到,但我真的不知道去哪里搜索

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

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

您可以在此处找到 'documentation':https://ci.apache.org/projects/httpd/trunk/doxygen/structrequest__rec.html#afecc56ea8fb015aa52477dba471a6612

r->headers_out 是一个 apr_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");