【Linux网络编程】Nginx -- 模块开发(HTTP 过滤模块)
Nginx-HTTP之ngx_http_top_header_filter
头插法与静态全局变量
ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain);
ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
ngx_int_t rc;
ngx_connection_t *c;
c = r->connection;
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http output filter \"%V?%V\"", &r->uri, &r->args);
rc = ngx_http_top_body_filter(r, in);
if (rc == NGX_ERROR) {
/* NGX_ERROR may be returned by any filter */
c->error = 1;
}
return rc;
}
typedef ngx_int_t (*ngx_http_output_body_filter_pt) (ngx_http_request_t *r, ngx_chain_t *chain);
ngx_http_output_body_filter_pt ngx_http_top_body_filter;
ngx_http_top_body_filter = ngx_http_copy_filter;
ngx_http_top_body_filter = ngx_http_postpone_filter;
ngx_http_top_body_filter = ngx_http_write_filter;
ngx_http_top_body_filter = ngx_http_addition_body_filter;
...
ngx_http_top_body_filter = ngx_http_sub_body_filter;
...
自定义的:
ngx_http_top_body_filter = ngx_http_subs_body_filter;
ngx_http_output_filter--->ngx_http_subs_body_filter-->