# Upstream\_response\_length yields zero, need content-length

**URL:** <https://www.ruby-forum.com/t/upstream-response-length-yields-zero-need-content-length/188860>\
**Category:** NGINX\
**Created:** [May 19, 2010, 2:53pm UTC](https://www.ruby-forum.com/t/upstream-response-length-yields-zero-need-content-length/188860 "2010-05-19T14:53:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 19, 2010, 2:53pm UTC](https://www.ruby-forum.com/t/upstream-response-length-yields-zero-need-content-length/188860/1 "2010-05-19T14:53:20Z")

</div>

hi all 🙂

i am trying to inject a content-length header into a response from an  
upstreamÂ because the upstream is not capable of sending a content-length  
since the size of the body is not known until the end is actually  
reached.

my current config is:

location / {  
Â Â proxy\_buffering on;  
Â Â proxy\_pass [http://upstream](http://upstream);  
Â Â chunked\_transfer\_encoding off;  
Â Â add\_header Content-Length $upstream\_response\_length;  
}

now when usingÂ upstream\_response\_length in the log\_format i get a  
non-zero value but when used in add\_header its zero.  
i needed to turn offÂ chunked\_transfer\_encoding because otherwise the  
client will choke.

nginx gives the warn log:Â an upstream response is buffered to a  
temporary file /var/tmp/nginx/proxy/1/00/0000000001 while reading  
upstream, […]Â so the response length should be known in this case.  
but i guess the problem is since this is with headers the response would  
have to be split first which should then yield a (new) variable like  
upstream\_body\_size or similar.

any help is highly appreciated.

thanks in advance.

greets,  
elm0Â
