加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

NGINX头部和身体过滤器模块

发布时间:2020-12-13 21:36:14 所属栏目:Nginx 来源:网络整理
导读:我一直在编写一个NGINX过滤器模块,可以读取/写入传入请求的cookie.如果未正确设置特定cookie(即身份验证cookie),则会将传出标头状态设置为相应的错误代码.这可以按照Evan Millers tutorial的方向正常工作.下一部分我正在尝试工作(并且到目前为止)是调用了体

我一直在编写一个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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读