NGINX Header and Housing Filter Modules

I encoded a NGINX filter module that can read / write cookies for incoming requests. If a particular cookie is not set correctly (i.e., an authentication cookie), it will set the status of the outgoing header to the corresponding error code. This works great in the direction of the Evan Miller tutorial . The next part, which I'm trying to work for (and still don't have), calls the body filter call, so I can insert / replace the body response text when there are error answers. I followed Evan Miller 's body filter tutorial again , and I can't work my whole life. Here is my setup:

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 ..

.

+6
1

, Evan http- ngx_http_<module_name>_header_filter().

http (r->headers_out.content_length_n), nginx-1.2.7.

.

0

All Articles