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,
ngx_http_source_cookie_init,
NULL,
NULL,
NULL,
NULL,
ngx_http_source_cookie_create_loc_conf,
ngx_http_source_cookie_merge_loc_conf
};
ngx_module_t ngx_http_source_cookie_module = {
NGX_MODULE_V1,
&ngx_http_source_cookie_module_ctx,
ngx_http_source_cookie_commands,
NGX_HTTP_MODULE,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NGX_MODULE_V1_PADDING
};
static ngx_int_t
ngx_http_source_cookie_header_filter(ngx_http_request_t *r)
{
...
}
static ngx_int_t
ngx_http_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
...
}
static ngx_int_t
ngx_http_source_cookie_init(ngx_conf_t *cf)
{
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 ..
.