Thanks, that information was priceless ;-)<div>It works like a charm now.</div><div><br></div><div>AM<br><br><div class="gmail_quote">On 30 May 2011 23:27, Maxim Dounin <span dir="ltr"><<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello!<br>
<div><div></div><div class="h5"><br>
On Mon, May 30, 2011 at 07:35:17PM +0100, Adelino Monteiro wrote:<br>
<br>
> Hello,<br>
><br>
> I'm writing my first module (actually a copy from mod_strip with some simple<br>
> modifications)<br>
><br>
> I have this simple function that for testing purposes should simply make a<br>
> simple substitution of all chars to A. I used gdb and chain_link->buf->start<br>
> indeed has all the characters replaced with A. However the output in the<br>
> end is the original file without any other modification.<br>
><br>
> Could someone shed some light on this mistery?<br>
><br>
> Thanks<br>
><br>
> AM<br>
><br>
> static ngx_int_t<br>
> ngx_http_strip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)<br>
> {<br>
> ngx_http_strip_ctx_t *ctx;<br>
> ngx_chain_t *chain_link;<br>
><br>
><br>
> u_char *reader;<br>
> u_char *writer;<br>
><br>
> ngx_log_t *log;<br>
><br>
> log = r->connection->log;<br>
><br>
> ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "In strip strip body filter 1<br>
> ");<br>
><br>
> ctx = ngx_http_get_module_ctx(r, ngx_http_strip_filter_module);<br>
> if (ctx == NULL) {<br>
> ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "In strip strip body<br>
> filter 2 ");<br>
> return ngx_http_next_body_filter(r, in);<br>
> }<br>
> ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "In strip strip body filter 3<br>
> ");<br>
><br>
><br>
> for (chain_link = in; chain_link; chain_link = chain_link->next) {<br>
> for (writer = chain_link->buf->pos, reader = chain_link->buf->pos;<br>
> reader < chain_link->buf->last; reader++) {<br>
> ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, "w: \"%c\"",<br>
> *reader);<br>
><br>
> *reader = 'A' ;<br>
> if (reader < chain_link->buf->last)<br>
> *writer++ = *reader;<br>
> }<br>
> ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, "In strip_body_filter<br>
> writer: \"%s\"", writer);<br>
><br>
> chain_link->buf->last = writer;<br>
><br>
> }<br>
><br>
> return ngx_http_next_body_filter(r, in);<br>
> }<br>
<br>
</div></div>If you want to modify buffer data in place, you have to:<br>
<br>
1. Request buffers to be in memory via r->filter_need_in_memory<br>
flag.<br>
<br>
2. Request buffers to be in temporary (i.e. modifiable) memory<br>
buffers via r->filter_need_temporary flag.<br>
<br>
Both (1) and (2) must be done at header filter stage.<br>
<br>
3. Reset buf->in_file flag as long as you modified data to stop<br>
nginx from sending file data (if any and enabled via sendfile<br>
directive) instead of corresponding memory contents.<br>
<br>
Please refer to charset filter sources for an example.<br>
<br>
Maxim Dounin<br>
<br>
_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
<a href="http://nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://nginx.org/mailman/listinfo/nginx-devel</a><br>
</blockquote></div><br></div>