Welcome! Log In Create A New Profile

Advanced

How to get access to a response header fields in a proxy_pass case

Posted by hkahlouche 
How to get access to a response header fields in a proxy_pass case
February 16, 2016 05:55PM
Hi,
I am trying to get access to a custom response header, save it into a variable, and get rid of it so that it will not be proxied back to the client. That variable is then used in the access logs.
Unfortunately, the following doesn't seem to work:

server {
listen 142.133.151.129:8090 default;

##Intial values for calculated access log variables
set $cache_status "-";
set $destination_addr "-";

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://my_upstream_server;

proxy_http_version 1.1;

proxy_max_temp_file_size 0; #size of the temp file when response doesn't fit in buffer

#Setting access log variables
if ($sent_http_x_cache = "HIT") {
set $cache_status "HIT";
}
if ($sent_http_x_cache != "HIT") {
set $cache_status "MISS";
}
set $destination_addr $sent_http_x_destination;
# now get rid of these response header fields
set $sent_http_x_destination "";
set $sent_http_x_cache "";
}

I am getting empty values for $sent_http_x_destination and $sent_http_x_cache.

Here is the curl request and response:

[root@CL10-RH66-lmchaka ~]# curl -Ov --range "100-1000000" http://142.133.151.129:8090/ao3/vod/soccer/worldcup2014/final1
< HTTP/1.1 206 Partial Content
< Server: openresty/1.9.3.1
< Date: Tue, 16 Feb 2016 22:25:32 GMT
< Content-Type: application/octet-stream
< Content-Length: 999901
< Connection: keep-alive
< Accept-Ranges: bytes
< Age: 660
< ETag: "3833945841"
< Content-Range: bytes 100-1000000/94371840
< X-Cache: HIT
< X-Destination: 142.133.151.94
<

I would appreciate if someone can help and provide a determistic way to see the response header fields and store them into variables.

Thanks
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 158
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready