Upstream_response_length yields zero, need content-length

hi all :slight_smile:

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

my current config is:

location / {
Ă‚ Ă‚ proxy_buffering on;
Ă‚ Ă‚ proxy_pass 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.