Hello, 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 ngx_write_chain_to_file or ngx_write_chain_to_temp_file functions to write the data to your file. An example of such a module is: https://trac.nginx.org/nginx/browser/nginx/src/http/modules/ngx_http_sub_filter_module.c#L282
http://www.evanmiller.org/nginx-modules-guide.html#filters-body 2015-09-08 18:43 GMT+03:00 hack988 <hack...@163.com>: > Hello, > I has already read ngx_http_proxy_module.c twice(source code version > 1.9.4),Sadness that i'm hadn't find ngx_write_chain_to_file or > ngx_write_chain_to_temp_file function in this source file. > I found other code: > > ================================================================================================= > line 1551 > for ( ;; ) { > ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, > "proxy output chunk: %d", ngx_buf_size(cl->buf)); > > size += ngx_buf_size(cl->buf); > > if (cl->buf->flush > || cl->buf->sync > || ngx_buf_in_memory(cl->buf) > || cl->buf->in_file) > { > tl = ngx_alloc_chain_link(r->pool); > if (tl == NULL) { > return NGX_ERROR; > } > > tl->buf = cl->buf; > *ll = tl; > ll = &tl->next; > } > > if (cl->next == NULL) { > break; > } > > cl = cl->next; > } > line 1653 > out: > > rc = ngx_chain_writer(&r->upstream->writer, out); > > I guss that nginx get response from buffer and rewrite output buffer > directly. > > =============================================================================================== > line 459 > { ngx_string("proxy_cache_path"), > NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE, > ngx_http_file_cache_set_slot, > NGX_HTTP_MAIN_CONF_OFFSET, > offsetof(ngx_http_proxy_main_conf_t, caches), > &ngx_http_proxy_module }, > > proxy_cache_path is set to ngx_http_proxy_main_conf_t->caches varible,but > it doesn't be used in proxy moudle's source code to write cache file. > > ================================================================================================= > What I want to do: > Nginx Call header,body handler like this: > header handle1->header handler2->body handler1->body hander2 > > Myself module is in: > header handle1->header handler2->body handler1->myself body handle->body > hander2 > > I want to save response buffer which body handler1 rewrite to a file. > > > > ------------------------------ > hack988 > > > *From:* Hung Nguyen <hun...@opensource.com.vn> > *Date:* 2015-09-08 11:01 > *To:* nginx-devel <nginx-devel@nginx.org> > *Subject:* Re: How to get Original response before gzip or another module > filter rewrite response > Hello, > > 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. > Many nginx modules already use these function, take a look at > ngx_http_proxy_module for more detail. > > — > Hưng > > > On Sep 7, 2015, at 9:07 PM, hack988 <hack...@163.com> wrote: > > Hello everybody: > Is Anyone can anwer my question? thanks very mach; > > ------------------------------ > hack988 > > > *From:* hack988 <hack...@163.com> > *Date:* 2015-09-05 21:20 > *To:* nginx-devel <nginx-devel@nginx.org> > *Subject:* How to get Original response before gzip or another module > filter rewrite response > Dear All: > I'm a beginner for nginx development,Although i'm read Emiller's Guide and > another article about Nginx develop for several days,I still don't know > how to read whole original response buffer chain copy to myself module's > temporary buffer,before another module(gzip,gunzip,gzip_static) rewrite > buffer. > How to check another module is written output buffer to diffrent content > type? > I want to copy buffer to a file that no compress or chunked. > I'm sorry for my poor english ,thx. > > ------------------------------ > hack988 > > _______________________________________________ > nginx-devel mailing list > nginx-devel@nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel > > > > _______________________________________________ > nginx-devel mailing list > nginx-devel@nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel >
_______________________________________________ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel