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