NGINX头部和身体过滤器模块

我一直在编写一个Nginx过滤器模块,可以读取/写入传入请求的cookie.如果未正确设置特定cookie(即身份验证cookie),则会将传出标头状态设置为相应的错误代码.这可以按照Evan Miller’s tutorial的方向正常工作.下一部分我正在尝试工作(并且到目前为止)是调用了体滤波器,因此我可以在遇到错误响应时插入/替换正文响应文本.我再次关注身体过滤器上的Evan Miller’s tutorial,我不能为我的生活得到这个工作.这是我的设置:

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.

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...