nginx模块开发入门(八)-3.3 Handler Installation

3.3. Handler Installation
3.3. Handler的装载


     Handler的装载通过往模块启用了的指令的回调函数中添加代码来完成。比如,例子circle gif 中 ngx_command_t是这样的:
      { ngx_string("circle_gif"),
      NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
      ngx_http_circle_gif,
      0,
      0,
      NULL }


     回调函数是里面的第三个元素,在这个例子中就是那个 ngx_http_circle_gif。回调函数的参数是由指令结构体( ngx_conf_t, 包含用户配置的参数),相应的 ngx_command_t结构体以及一个指向模块自定义配置结构体的指针组成的。我的circle gif模块中,这些函数是这样子的:
static char *
ngx_http_circle_gif(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
    ngx_http_core_loc_conf_t  *clcf;

    clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
    clcf->handler = ngx_http_circle_gif_handler;

    return NGX_CONF_OK;
}


     这里可以分为两步:首先,得到当前location的“core”结构体,再分配给它一个 handler。很简单,不是吗?

     我已经把我知道的关于hanler模块的东西全招了,现在可以来说说输出过滤链上的filter模块了。

猜你喜欢

转载自running.iteye.com/blog/1936750