微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.

原文地址:https://www.jb51.cc/nginx/434416.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐