<div dir="ltr">Hello,<div>You need to create a response body filter module. Your filter handler is called every time some response data is received from the upstream. In that handler you can use the <span style="font-size:12.8000001907349px">ngx_write_chain_to_file or ngx_write_chain_to_temp_file functions to write the data to your file. </span><br></div><div><span style="font-size:12.8000001907349px">An example of such a module is:</span></div><div><a href="https://trac.nginx.org/nginx/browser/nginx/src/http/modules/ngx_http_sub_filter_module.c#L282">https://trac.nginx.org/nginx/browser/nginx/src/http/modules/ngx_http_sub_filter_module.c#L282</a><br></div><div><br></div><div><a href="http://www.evanmiller.org/nginx-modules-guide.html#filters-body">http://www.evanmiller.org/nginx-modules-guide.html#filters-body</a><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-09-08 18:43 GMT+03:00 hack988 <span dir="ltr"><<a href="mailto:hack988@163.com" target="_blank">hack988@163.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
<div><span></span>Hello, </div><div>I has already read ngx_http_proxy_module.c twice(source code version 1.9.4),Sadness that i'm hadn't find <span style="font-size:10.5pt;line-height:1.5;background-color:window">ngx_write_chain_to_file or ngx_write_chain_to_temp_file function in this source file.</span></div><div>I found other code:</div><div>=================================================================================================</div><div><span style="background-color:rgba(0,0,0,0)">line 1551</span></div><div><span style="background-color:rgba(0,0,0,0)">  for ( ;; ) {
<br>        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
<br>                       "proxy output chunk: %d", ngx_buf_size(cl->buf));
<br>
<br>        size += ngx_buf_size(cl->buf);
<br>
<br>        if (cl->buf->flush
<br>            || cl->buf->sync
<br>            || ngx_buf_in_memory(cl->buf)
<br>            || cl->buf->in_file)
<br>        {
<br>            tl = ngx_alloc_chain_link(r->pool);
<br>            if (tl == NULL) {
<br>                return NGX_ERROR;
<br>            }
<br>
<br>            tl->buf = cl->buf;
<br>            *ll = tl;
<br>            ll = &tl->next;
<br>        }
<br>
<br>        if (cl->next == NULL) {
<br>            break;
<br>        }
<br>
<br>        cl = cl->next;
<br>    } <br></span></div><div><span style="background-color:rgba(0,0,0,0)">line 1653</span></div><div><span style="background-color:rgba(0,0,0,0)">out:
<br>
<br>    rc = ngx_chain_writer(&r->upstream->writer, out);</span></div><div><br></div>
<div>I guss that nginx get response from buffer and rewrite output buffer directly.</div><div>===============================================================================================</div><div>line 459</div><div><span style="background-color:rgba(0,0,0,0)">   { ngx_string("proxy_cache_path"),
<br>      NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE,
<br>      ngx_http_file_cache_set_slot,
<br>      NGX_HTTP_MAIN_CONF_OFFSET,
<br>      offsetof(ngx_http_proxy_main_conf_t, caches),
<br>      &ngx_http_proxy_module },</span></div><div><span style="background-color:rgba(0,0,0,0)"><br></span></div><div><span style="font-size:10.5pt;line-height:1.5;background-color:window">proxy_cache_path is set to </span><span style="font-size:10.5pt;line-height:1.5;background-color:window">ngx_http_proxy_main_conf_t-></span><span style="font-size:10.5pt;line-height:1.5;background-color:window">caches varible,but it doesn't be used in proxy moudle's source code to write cache file.</span></div><div><span style="font-size:10.5pt;line-height:1.5;background-color:window">=================================================================================================</span></div><div>What I want to do:</div><div>Nginx Call header,body handler like this:</div><div>header handle1->header handler2->body handler1->body hander2 </div><div><span style="font-size:10.5pt;line-height:1.5;background-color:window"><br></span></div><div>Myself module is in:</div><div>header handle1->header handler2->body handler1->myself body handle->body hander2 </div><div><br></div><div>I want to save response buffer which <span style="font-size:10.5pt;line-height:1.5;background-color:window">body handler1 rewrite to a file.</span></div><div><span style="font-size:10.5pt;line-height:1.5;background-color:window"><br></span></div><div><span style="font-size:10.5pt;line-height:1.5;background-color:window"> </span></div><div><br></div>
<hr style="WIDTH:210px;min-height:1px" align="left" color="#b5c4df" size="1">
<div><span>hack988</span></div><blockquote style="margin-top:0px;margin-bottom:0px;margin-left:0.5em"><div> </div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm"><div style="PADDING-RIGHT:8px;PADDING-LEFT:8px;FONT-SIZE:12px;FONT-FAMILY:tahoma;COLOR:#000000;BACKGROUND:#efefef;PADDING-BOTTOM:8px;PADDING-TOP:8px"><div><b>From:</b> <a href="mailto:hungnv@opensource.com.vn" target="_blank">Hung Nguyen</a></div><div><b>Date:</b> 2015-09-08 11:01</div><div><b>To:</b> <a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel</a></div><div><b>Subject:</b> Re: How to get Original response before gzip or another module filter rewrite response</div></div></div><div><div class="h5"><div><div><div>Hello,</div><div><br></div><div>I don’t know which context you are trying to do, but in order to write a chain buffer (this’s what contain nginx’s response) to file, you can use ngx_write_chain_to_file or ngx_write_chain_to_temp_file function. </div><div>Many nginx modules already use these function, take a look at ngx_http_proxy_module for more detail. </div><div><br></div><div>—</div><div>Hưng</div><div><br></div><br><div><blockquote type="cite" style="margin-top:0px"><div>On Sep 7, 2015, at 9:07 PM, hack988 <<a href="mailto:hack988@163.com" target="_blank">hack988@163.com</a>> wrote:</div><br><div><div style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:21px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span></span>Hello everybody:</div><div style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:21px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="background-color:rgba(0,0,0,0);font-size:10.5pt;line-height:1.5">   </span><span style="background-color:rgba(0,0,0,0)"><span> </span>Is Anyone can anwer my question? thanks very mach; </span> </div><div style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:21px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"> </div><hr align="left" size="1" style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:21px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;width:210px;min-height:1px"><div style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:21px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span>hack988</span></div><blockquote style="margin-top:0px;margin-bottom:0px;margin-left:0.5em;font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:21px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div> </div><div style="border-style:solid none none;border-top-color:rgb(181,196,223);border-top-width:1pt;padding:3pt 0cm 0cm"><div style="padding:8px;font-size:12px;font-family:tahoma;background-color:rgb(239,239,239)"><div><b>From:</b> <a href="mailto:hack988@163.com" target="_blank">hack988</a></div><div><b>Date:</b> 2015-09-05 21:20</div><div><b>To:</b> <a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel</a></div><div><b>Subject:</b> How to get Original response before gzip or another module filter rewrite response</div></div></div><div><div><div><span></span> Dear All:</div><div><span style="background-color:rgba(0,0,0,0)">    I'm a beginner for nginx development,</span><span style="background-color:rgba(0,0,0,0);font-size:10.5pt;line-height:1.5">Although </span><span style="font-size:10.5pt;line-height:1.5;background-color:rgba(0,0,0,0)">i'm read </span><span style="font-size:10.5pt;line-height:1.5;background-color:rgba(0,0,0,0)">Emiller's Guide</span><span style="font-size:10.5pt;line-height:1.5;background-color:rgba(0,0,0,0)"> and another article about Nginx develop for </span><span style="background-color:rgba(0,0,0,0);font-size:10.5pt;line-height:1.5">several days,I still don't know how to read </span><span style="background-color:rgba(0,0,0,0);font-size:10.5pt;line-height:1.5">whole o</span><span style="background-color:rgba(0,0,0,0);font-size:10.5pt;line-height:1.5">riginal </span><span style="font-size:10.5pt;line-height:1.5;background-color:rgba(0,0,0,0)">response buffer chain<span> </span></span><span style="font-size:10.5pt;line-height:1.5;background-color:rgba(0,0,0,0)">copy to myself module's </span><span style="font-size:10.5pt;line-height:1.5;background-color:rgba(0,0,0,0)">temporary </span><span style="font-size:10.5pt;line-height:1.5;background-color:rgba(0,0,0,0)">buffer,before another module(gzip,gunzip,gzip_static) rewrite buffer.</span></div><div>How to check another module is written output buffer to diffrent content type?</div><div>I want to copy buffer to a file that no compress or chunked.</div><div>I'm sorry for my <span style="background-color:rgba(0,0,0,0)"><span> </span>poor </span>english ,thx.</div><div> </div><hr align="left" size="1" style="width:210px;min-height:1px"><div><span>hack988</span></div></div></div></blockquote><span style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:21px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">_______________________________________________</span><br style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:21px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:21px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">nginx-devel mailing list</span><br style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:21px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:21px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a></span><br style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:21px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:21px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a></span></div></blockquote></div><br></div></div></div></div></blockquote>
</div><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" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br></blockquote></div><br></div>