gpt4 book ai didi

module - NGINX Header 和 Body 过滤器模块

转载 作者:行者123 更新时间:2023-12-04 16:12:03 28 4
gpt4 key购买 nike

我一直在编写一个 NGINX 过滤器模块,它可以读取/写入传入请求的 cookie。如果特定 cookie 设置不正确(即身份验证 cookie),它会将传出 header 状态设置为适当的错误代码。根据 Evan Miller's tutorial 的指示,这可以正常工作.我试图开始工作的下一部分(到目前为止还没有)是调用正文过滤器,以便在遇到错误响应时插入/替换正文响应文本。我又关注了Evan Miller's tutorial在 body 过滤器上,我这辈子都做不到。这是我的设置:

static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
...
...


static ngx_http_module_t ngx_http_source_cookie_module_ctx = {
NULL, /* preconfiguration */
ngx_http_source_cookie_init, /* postconfiguration */

NULL, /* create main configuration */
NULL, /* init main configuration */

NULL, /* create server configuration */
NULL, /* merge server configuration */

ngx_http_source_cookie_create_loc_conf, /* create location configuration */
ngx_http_source_cookie_merge_loc_conf /* merge location configuration */
};

ngx_module_t ngx_http_source_cookie_module = {
NGX_MODULE_V1,
&ngx_http_source_cookie_module_ctx, /* module context */
ngx_http_source_cookie_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
NULL, /* init module */
NULL, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
NULL, /* exit process */
NULL, /* exit master */
NGX_MODULE_V1_PADDING
};
/*--------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------*/
static ngx_int_t
ngx_http_source_cookie_header_filter(ngx_http_request_t *r)
{
// this gets invoked
...
}

/*--------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------*/
static ngx_int_t
ngx_http_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
// this never get invoked
...
}

/*--------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------*/
static ngx_int_t
ngx_http_source_cookie_init(ngx_conf_t *cf)
{
// registering of my filters

ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_source_cookie_header_filter;

ngx_http_next_body_filter = ngx_http_top_body_filter;
ngx_http_top_body_filter = ngx_http_body_filter;

return NGX_OK;
}

这是我的基本设置,据我所知,它出现在我遇到的所有示例/教程中。我想知道我是否需要启用一些完全不同的东西......比如 NGINX 配置选项、NGINX ./configure 编译选项等。

任何帮助是极大的赞赏。

最佳答案

我注意到 Evan 没有修复 ngx_http_<module_name>_header_filter() 中的 http 内容长度。 .

如果我不添加 http 内容长度(r->headers_out.content_length_n),插入到请求末尾的文本将不会从 nginx-1.2.7 stable 输出。

你也可以看到footer filter module .

关于module - NGINX Header 和 Body 过滤器模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11103514/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com