Thank you Simon,<div><br></div><div>Now the filter is engaged and works.</div><div><br></div><div>Thank you so much.</div><div><br clear="all">Walter <br><br>
<br><br><div class="gmail_quote">On 9 October 2011 04:00, Simon Liu <span dir="ltr"><<a href="mailto:simohayha.bobo@gmail.com">simohayha.bobo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
You should use HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES <font face="'courier new', monospace">ngx_http_corley_filter_module</font>" <span style="color:rgb(0, 0, 0);font-family:'Microsoft YaHei';font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:nowrap;word-spacing:0px">rather than</span> <font face="'courier new', monospace">HTTP_MODULES="$HTTP_MODULES ngx_http_corley_filter_module"</font><br>
<br><div class="gmail_quote"><div><div></div><div class="h5">On Sun, Oct 9, 2011 at 5:42 AM, Walter Dal Mut <span dir="ltr"><<a href="mailto:info@walterdalmut.com" target="_blank">info@walterdalmut.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div class="h5">
<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 face="'courier new', monospace">ngx_addon_name=ngx_http_corley_filter_module</font></div><div><font face="'courier new', monospace">HTTP_MODULES="$HTTP_MODULES ngx_http_corley_filter_module"</font></div>
<div><font 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 style="color:rgb(34, 34, 34);font-size:13px;background-color:rgb(255, 255, 255)"><font 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"><font color="#888888">Walter<br>
</font><br></div></div>_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br></blockquote></div><font color="#888888"><br><br clear="all"><br>-- <br>douban:<a href="http://www.douban.com/people/mustang/" target="_blank">www.douban.com/people/mustang/</a><br>
<br>blog: <a href="http://www.pagefault.info" target="_blank">www.pagefault.info</a><br><br>twitter: <a href="http://www.twitter.com/minibobo" target="_blank">www.twitter.com/minibobo</a><br><br>weibo: <a href="http://www.weibo.com/diaoliang" target="_blank">www.weibo.com/diaoliang</a><br>
<br>
</font><br>_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br></blockquote></div><br></div>