# Response header from fcgi server

**URL:** <https://www.ruby-forum.com/t/response-header-from-fcgi-server/232082>\
**Category:** NGINX\
**Created:** [September 17, 2014, 7:50am UTC](https://www.ruby-forum.com/t/response-header-from-fcgi-server/232082 "2014-09-17T07:50:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [September 17, 2014, 7:50am UTC](https://www.ruby-forum.com/t/response-header-from-fcgi-server/232082/1 "2014-09-17T07:50:24Z")

</div>

Hi,

PHP-application sends response with HTTP header X-Language and I need  
pass this to nginx.  
With Firebug I see this header, but variable $http\_x\_language or  
$sent\_http\_x\_language is empty.

What I am doing wrong?

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [September 17, 2014, 8:36am UTC](https://www.ruby-forum.com/t/response-header-from-fcgi-server/232082/2 "2014-09-17T08:36:37Z")

</div>

— Original message —  
From: “wishmaster” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: 17 September 2014, 08:49:51

> Hi,
> 
> PHP-application sends response with HTTP header X-Language and I need pass this  
> to nginx.  
> With Firebug I see this header, but variable $http\_x\_language or  
> $sent\_http\_x\_language is empty.
> 
> What I am doing wrong?

Hmm… Interesting.  
I have changed header from “X-Language” to something like “Currlang”  
and now I see variable $sent\_http\_currlang.

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [September 17, 2014, 9:07am UTC](https://www.ruby-forum.com/t/response-header-from-fcgi-server/232082/3 "2014-09-17T09:07:27Z")

</div>

On Wed, Sep 17, 2014 at 08:49:36AM +0300, wishmaster wrote:

Hi there,

> PHP-application sends response with HTTP header X-Language and I need pass this  
> to nginx.  
> With Firebug I see this header, but variable $http\_x\_language or  
> $sent\_http\_x\_language is empty.
> 
> What I am doing wrong?

$http\_x\_language is a request header field – what the client sent  
to nginx.

$sent\_http\_x\_language is a response header field – what nginx sent to  
the client.

$upstream\_http\_x\_language would be what an upstream sent to nginx.

What do you do? What do you see? What do you expect to see?

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [September 17, 2014, 4:22pm UTC](https://www.ruby-forum.com/t/response-header-from-fcgi-server/232082/4 "2014-09-17T16:22:33Z")

</div>

— Original message —  
From: “wishmaster” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: 17 September 2014, 10:21:03

> > $sent\_http\_x\_language is a response header field – what nginx sent to

My problem is still actual.  
I am attempting to use http header from fastcgi server as part of  
cache key.  
$upstream\_http\_x\_language contains value, but empty in cache key

Part of cached page:

KEY: httpGETexample.comfoto-video-audio/videoUAH  
▒Expires: Thu, 19 Nov 1981 08:52:00 GMT  
Pragma: no-cache  
Content-Type: text/html; charset=utf-8  
Last-Modified: Wed, 17 Sep 2014 13:59:43 GMT  
Cache-Control: private  
X-Language: uk  
X-Accel-Buffering: yes

key must be  
httpGETexample.comfoto-video-audio/videoukUAH

–  
w

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [September 17, 2014, 9:21am UTC](https://www.ruby-forum.com/t/response-header-from-fcgi-server/232082/5 "2014-09-17T09:21:38Z")

</div>

— Original message —  
From: “Francis D.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: 17 September 2014, 10:06:47

> to nginx.
> 
> $sent\_http\_x\_language is a response header field – what nginx sent to  
> the client.
> 
> $upstream\_http\_x\_language would be what an upstream sent to nginx.
> 
> What do you do? What do you see? What do you expect to see?

Oh Francis, you help save me a lot of time as always, thanks.  
I did not know about $upstream\_\* variable

Without fastcgi caching, $sent\_http\_x\_language is not empty, but if  
chaching is “ON”, $sent\_http\_x\_language variable is empty. But  
$upstream\_\* contain expected data.

Thanks a lot!

–  
Cheers,  
Vitaliy

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [September 17, 2014, 4:29pm UTC](https://www.ruby-forum.com/t/response-header-from-fcgi-server/232082/6 "2014-09-17T16:29:59Z")

</div>

On Wed, Sep 17, 2014 at 05:22:14PM +0300, wishmaster wrote:

Hi there,

> My problem is still actual.  
> I am attempting to use http header from fastcgi server as part of cache key.  
> $upstream\_http\_x\_language contains value, but empty in cache key

How should that work?

A request comes in to nginx.

nginx creates the cache key to see if it should serve the request from  
cache, or should pass the request along to upstream and store the  
response  
in cache.

If you try to put something into your cache key that nginx can only know  
about after the request has been passed upstream, you are going to have  
a problem.

> Part of cached page:
> 
> KEY: httpGETexample.comfoto-video-audio/videoUAH

> key must be  
> httpGETexample.comfoto-video-audio/videoukUAH

Why does this matter?

What two requests would lead to upstream sending content with a  
different  
language? Use whatever is different in those requests in your cache key.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [September 18, 2014, 12:09am UTC](https://www.ruby-forum.com/t/response-header-from-fcgi-server/232082/7 "2014-09-18T00:09:17Z")

</div>

On Wed, Sep 17, 2014 at 05:42:18PM +0300, wishmaster wrote:

> > What two requests would lead to upstream sending content with a different  
> > language? Use whatever is different in those requests in your cache key.
> 
> At this time cache key uses $cookie\_language, this works as expected. But I do  
> not understand why with $http\_ or $upstream\_ does not work.

$http\_ comes from the client, so should work.

$upstream\_ is empty until after upstream has responded, which is too  
late to be used in a cache key.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [September 17, 2014, 4:42pm UTC](https://www.ruby-forum.com/t/response-header-from-fcgi-server/232082/8 "2014-09-17T16:42:56Z")

</div>

— Original message —  
From: “Francis D.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: 17 September 2014, 17:29:43

> A request comes in to nginx.
> 
> nginx creates the cache key to see if it should serve the request from  
> cache, or should pass the request along to upstream and store the response  
> in cache.
> 
> If you try to put something into your cache key that nginx can only know  
> about after the request has been passed upstream, you are going to have  
> a problem.

I know how this works.

> What two requests would lead to upstream sending content with a different  
> language? Use whatever is different in those requests in your cache key.

At this time cache key uses $cookie\_language, this works as expected.  
But I do not understand why with $http\_ or $upstream\_ does not work.
