<div>Hi everybody I am new to nginx and actually I am interested on nginx extensions.</div><div><br></div><div>I need to write a new module for nginx and compile a version with this module. I don't want to write down an handler but a filter, I need to work on headers.</div>

<div><br></div><div>For that reason I start my module using gzip as a base and cut different part that I don't want use.</div><div><br></div><div>I compile nginx with my module and all works fine. After that I start the server with my personal configuration (corley on;) in the main conf file and the server start correctly. The problem is that my module seems never used. The filter functionality is pretty simple, I want to force text/plain header.</div>

<div><br></div><div>I don't understand why my module is never called. Any one can help me?</div><div><br></div><div>The main filename is: <i>ngx_http_corley_filter_module.c</i></div><div>The configuration filename is:<i> config</i></div>

<div><i><br></i></div><div>The config content:</div><div><i><br></i></div><div><div><font class="Apple-style-span" face="'courier new', monospace">ngx_addon_name=ngx_http_corley_filter_module</font></div><div><font class="Apple-style-span" face="'courier new', monospace">HTTP_MODULES="$HTTP_MODULES ngx_http_corley_filter_module"</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_corley_filter_module.c"</font></div><div style="font-style: italic; "><br></div>

</div><div><br></div><div>The ngx_http_corley_filter_module.c content:</div><div><br></div><div><span class="Apple-style-span" style="color: rgb(34, 34, 34); font-size: 13px; background-color: rgb(255, 255, 255); "><font class="Apple-style-span" face="'courier new', monospace">#include <ngx_config.h><br>

#include <ngx_core.h><br>#include <ngx_http.h><br><br>typedef struct {<br>   ngx_flag_t           enable;<br>} ngx_http_corley_conf_t;<br><br>static ngx_int_t ngx_http_corley_filter_init(ngx_conf_t *cf);<br>static void * ngx_http_corley_create_conf(ngx_conf_t *cf);<br>

static char * ngx_http_corley_merge_conf(ngx_conf_t *cf, void *parent, void *child);<br>static void * ngx_http_corley_create_conf(ngx_conf_t *cf);<br><br>static ngx_command_t  ngx_http_corley_filter_commands[] = {<br><br>

   { ngx_string("corley"),<br>     NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_FLAG,<br>     ngx_conf_set_flag_slot,<br>     NGX_HTTP_LOC_CONF_OFFSET,<br>     offsetof(ngx_http_corley_conf_t, enable),<br>

     NULL },<br><br>     ngx_null_command<br>};<br><br><br>static ngx_http_module_t  ngx_http_corley_filter_module_ctx = {<br>   NULL,                                  /* preconfiguration */<br>   ngx_http_corley_filter_init,           /* postconfiguration */<br>

   NULL,                                  /* create main configuration */<br>   NULL,                                  /* init main configuration */<br>   NULL,                                  /* create server configuration */<br>

   NULL,                                  /* merge server configuration */<br>   ngx_http_corley_create_conf,           /* create location configuration */<br>   ngx_http_corley_merge_conf             /* merge location configuration */<br>

};<br><br><br>ngx_module_t  ngx_http_corley_filter_module = {<br>   NGX_MODULE_V1,<br>   &ngx_http_corley_filter_module_ctx,      /* module context */<br>   ngx_http_corley_filter_commands,         /* module directives */<br>

   NGX_HTTP_MODULE,                       /* module type */<br>   NULL,                                  /* init master */<br>   NULL,                                  /* init module */<br>   NULL,                                  /* init process */<br>

   NULL,                                  /* init thread */<br>   NULL,                                  /* exit thread */<br>   NULL,                                  /* exit process */<br>   NULL,                                  /* exit master */<br>

   NGX_MODULE_V1_PADDING<br>};<br><br><br>static ngx_http_output_header_filter_pt  ngx_http_next_header_filter;<br>static ngx_http_output_body_filter_pt    ngx_http_next_body_filter;<br><br><br><b>static ngx_int_t<br>ngx_http_corley_header_filter(ngx_http_request_t *r)<br>

{<br>   ngx_http_corley_conf_t  *conf;<br>   conf = ngx_http_get_module_loc_conf(r, ngx_http_corley_filter_module);<br><br>   ngx_table_elt_t       *h;<br><br>   h = ngx_list_push(&r->headers_out.headers);<br>   if (h == NULL) {<br>

       return NGX_ERROR;<br>   }<br><br>   h->hash = 1;<br>   ngx_str_set(&h->key, "Content-Encoding");<br>   ngx_str_set(&h->value, "text/plain");<br><br>   r->headers_out.content_encoding = h;<br>

<br>   r->main_filter_need_in_memory = 1;<br><br>   ngx_http_clear_content_length(r);<br>   ngx_http_clear_accept_ranges(r);<br><br><br>   return ngx_http_next_header_filter(r);<br>}<br></b><br><br>static ngx_int_t<br>

ngx_http_corley_body_filter(ngx_http_request_t *r, ngx_chain_t *in)<br>{<br>   ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,<br>             "not well formed XML document");<br>   return ngx_http_next_body_filter(r, in);<br>

}<br><br>static void *<br>ngx_http_corley_create_conf(ngx_conf_t *cf)<br>{<br>   ngx_http_corley_conf_t  *conf;<br><br>   conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_corley_conf_t));<br>   if (conf == NULL) {<br>       return NULL;<br>

   }<br><br>   /*<br>    * set by ngx_pcalloc():<br>    *<br>    *     conf->bufs.num = 0;<br>    *     conf->types = { NULL };<br>    *     conf->types_keys = NULL;<br>    */<br><br>   conf->enable = NGX_CONF_UNSET;<br>

<br>   return conf;<br>}<br><br><br>static char *<br>ngx_http_corley_merge_conf(ngx_conf_t *cf, void *parent, void *child)<br>{<br>   ngx_http_corley_conf_t *prev = parent;<br>   ngx_http_corley_conf_t *conf = child;<br>
<br>
   ngx_conf_merge_value(conf->enable, prev->enable, 0);<br><br>   return NGX_CONF_OK;<br>}<br><br>static ngx_int_t<br>ngx_http_corley_filter_init(ngx_conf_t *cf)<br>{<br>   ngx_http_next_header_filter = ngx_http_top_header_filter;<br>

   ngx_http_top_header_filter = ngx_http_corley_header_filter;<br><br>   ngx_http_next_body_filter = ngx_http_top_body_filter;<br>   ngx_http_top_body_filter = ngx_http_corley_body_filter;<br><br>   return NGX_OK;<br>}</font></span></div>

<div><br></div>Thanks to all.<br clear="all">Walter<br>