Module NGINX收割台和车身滤清器模块

Module NGINX收割台和车身滤清器模块,module,filter,nginx,Module,Filter,Nginx,我一直在编写一个NGINX过滤模块,它可以读取/写入传入请求的cookies。如果未正确设置特定cookie(即身份验证cookie),则会将传出标头状态设置为相应的错误代码。根据的指示,此操作非常有效。下一部分我将尝试工作(到目前为止还没有)是调用body过滤器,以便在遇到错误响应时插入/替换body响应文本。我又一次使用了身体过滤器,我一辈子都不能让它工作。以下是我的设置: static ngx_http_output_header_filter_pt ngx_http_next_heade

我一直在编写一个NGINX过滤模块,它可以读取/写入传入请求的cookies。如果未正确设置特定cookie(即身份验证cookie),则会将传出标头状态设置为相应的错误代码。根据的指示,此操作非常有效。下一部分我将尝试工作(到目前为止还没有)是调用body过滤器,以便在遇到错误响应时插入/替换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\u http\u header\u filter()中修复http内容长度。

如果我不添加http内容长度(
r->headers\u out.content\u length\u n
),则在请求末尾插入的文本将不会从nginx-1.2.7中输出


您还可以看到。

您正在使用的NGINX版本是什么?您使用了什么/配置参数?我在尝试运行稳定版本的body filter模块时遇到了类似的问题,然后我尝试了dev版本(1.3.5),结果成功了(不知道为什么)。