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">&lt;<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>&gt;</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>
&gt; Hello,<br>
&gt;<br>
&gt; I&#39;m writing my first module (actually a copy from mod_strip with some simple<br>
&gt; modifications)<br>
&gt;<br>
&gt; I have this simple function that for testing purposes should simply make a<br>
&gt; simple substitution of all chars to A. I used gdb and chain_link-&gt;buf-&gt;start<br>
&gt; indeed has all the  characters replaced with A. However the output in the<br>
&gt; end is the original file without any other modification.<br>
&gt;<br>
&gt; Could someone shed some light on this mistery?<br>
&gt;<br>
&gt; Thanks<br>
&gt;<br>
&gt; AM<br>
&gt;<br>
&gt; static ngx_int_t<br>
&gt; ngx_http_strip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)<br>
&gt; {<br>
&gt;     ngx_http_strip_ctx_t *ctx;<br>
&gt;     ngx_chain_t          *chain_link;<br>
&gt;<br>
&gt;<br>
&gt;     u_char *reader;<br>
&gt;     u_char *writer;<br>
&gt;<br>
&gt;     ngx_log_t   *log;<br>
&gt;<br>
&gt;     log = r-&gt;connection-&gt;log;<br>
&gt;<br>
&gt;     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, &quot;In strip strip body filter 1<br>
&gt; &quot;);<br>
&gt;<br>
&gt;     ctx = ngx_http_get_module_ctx(r, ngx_http_strip_filter_module);<br>
&gt;     if (ctx == NULL) {<br>
&gt;         ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, &quot;In strip strip body<br>
&gt; filter 2 &quot;);<br>
&gt;         return ngx_http_next_body_filter(r, in);<br>
&gt;     }<br>
&gt;     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, &quot;In strip strip body filter 3<br>
&gt; &quot;);<br>
&gt;<br>
&gt;<br>
&gt;     for (chain_link = in; chain_link; chain_link = chain_link-&gt;next) {<br>
&gt;         for (writer = chain_link-&gt;buf-&gt;pos, reader = chain_link-&gt;buf-&gt;pos;<br>
&gt; reader &lt; chain_link-&gt;buf-&gt;last; reader++) {<br>
&gt;             ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, &quot;w: \&quot;%c\&quot;&quot;,<br>
&gt; *reader);<br>
&gt;<br>
&gt;             *reader = &#39;A&#39; ;<br>
&gt;             if (reader &lt; chain_link-&gt;buf-&gt;last)<br>
&gt;                         *writer++ = *reader;<br>
&gt;         }<br>
&gt;             ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, &quot;In strip_body_filter<br>
&gt; writer: \&quot;%s\&quot;&quot;, writer);<br>
&gt;<br>
&gt;         chain_link-&gt;buf-&gt;last = writer;<br>
&gt;<br>
&gt;     }<br>
&gt;<br>
&gt;     return ngx_http_next_body_filter(r, in);<br>
&gt; }<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-&gt;filter_need_in_memory<br>
flag.<br>
<br>
2. Request buffers to be in temporary (i.e. modifiable) memory<br>
buffers via r-&gt;filter_need_temporary flag.<br>
<br>
Both (1) and (2) must be done at header filter stage.<br>
<br>
3. Reset buf-&gt;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>