How to get Original response before gzip or another module filter rewrite response

hack988 hack988 at
Tue Sep 8 15:43:34 UTC 2015

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) { 

cl = cl->next; 
line 1653

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"), 
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.


From: Hung Nguyen
Date: 2015-09-08 11:01
To: nginx-devel
Subject: Re: How to get Original response before gzip or another module filter rewrite response

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. 


On Sep 7, 2015, at 9:07 PM, hack988 <hack988 at> wrote:

Hello everybody:
    Is Anyone can anwer my question? thanks very mach;  

From: hack988
Date: 2015-09-05 21:20
To: nginx-devel
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.

nginx-devel mailing list
nginx-devel at

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx-devel mailing list