<div dir="ltr"><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 27, 2013 at 10:21 PM, Maxim Dounin <span dir="ltr"><<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello!<br>
<div><div class="h5"><br>
On Tue, Aug 27, 2013 at 11:21:38AM +0800, 邓尧 wrote:<br>
<br>
> Hi,<br>
> I'm writing an nginx module, it does something similar to the sub module.<br>
> After some research I succeeded in handling the ngx_chain_t pointer passed<br>
> to my body filter. My module seems to work well for static files.<br>
> When my module is handling PHP responses (fastcgi), sometimes the<br>
> ngx_chain_t pointer is NULL. I simply call the next body filter in such<br>
> situation like the sub module body filter. However function<br>
> ngx_http_write_filter() will fail, because r->out isn't NULL<br>
> and the buf's in r->out are of zero size.<br>
> My questions are: what's the meaning of r->out? how should I modify it in<br>
> my body filter ? Could I simply return NGX_OK in my body filter without<br>
> calling the next body filter if the ngx_chain_t pointer is NULL ?<br>
<br>
</div></div>The r->out is write filter's private data, you shouldn't touch it<br>
in your module. And it shouldn't contain zero size non-special<br>
buffers, if it does - there is a bug somewhere (most likely in<br>
your filter).<br>
<span class=""><font color="#888888"><br>
--<br>
Maxim Dounin<br>
<a href="http://nginx.org/en/donation.html" target="_blank">http://nginx.org/en/donation.html</a><br>
<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></font></span></blockquote></div><br><div>What are the most likely reasons for a buffer in r->out to be
zero sized and non-special ? I do believe the bug is somewhere in my
body filter, but I checked many times, cannot find it. My body filter's work flow is like the following:<br></div><div>1. create a private empty chain, ctx->out.<br></div><div>2. search the input chain for patterns<br>
</div><div>3.
if a matched pattern is found, append three ngx_buf_t structures (one
for the substitution string, two for the data surrounding the matched
pattern) to ctx->out, the one used for the substitution string is zerorized then only three members are set: pos, last, memory. The other two are memcpy()ed from the original buffer then:<br></div><div> * pos, last, file_pos, file_last are modified accordingly<br>
</div><div> * last_buf, last_in_chain are cleared (last_buf & last_in_chain of the final chain are still set)<br></div><div> * shadow is set to NULL<br></div><div>4. if no pattern is found, append the ngx_buf_t structure to ctx->out, then clear last_buf & last_in_chain.<br>
</div><div>5. when a pattern is across two buffers, well, it's ignored, should be no problem.<br></div><div>6. feed ctx->out to the next body filter<br></div><div>7. return the code from the above function call after some cleaning up.<br>
</div></div></div></div>