share_all_vars
specify whether to share all the Nginx variables of the subrequest with the current (parent) request. modifications of the Nginx variables in the subrequest will affect the current (parent) request. Enabling this option may lead to hard-to-debug issues due to bad side-effects and is considered bad and harmful. Only enable this option when you completely know what you are doing.I tried both share_all_vars and the header idea. Unfortunately neither of those actually work.
Even with ngx.location.capture('/bar', {share_all_vars = true}), I don't see upstream variables being set. Are those variables not shared?
If I set upstream response time as a header "more_set_headers 'Upstream_time: $upstream_response_time';", it results in a really strange value e.g. Upstream_time: 1507915223.173 while its recorded in access log correctly as -
"127.0.0.1 - - [13/Oct/2017:10:20:23 -0700] "GET /bar HTTP/1.1" 200 14 "-" "curl/7.54.0" "-" "0.086" "0.086""
server {listen 8081;server_name localhost;location / {content_by_lua_block {local res = ngx.location.capture("/proxy", { share_all_vars = true })ngx.say(ngx.var.my_upstream_response_time)}}location /proxy {set $my_upstream_response_time "";proxy_pass http://127.0.0.1:8082/;body_filter_by_lua_block {if ngx.arg[2] == true thenngx.var.my_upstream_response_time = ngx.var.upstream_response_timeend}}}server {listen 8082;server_name _;location / {return 200 "Plain";}}
Thanks a lot for looking into this.
I am assuming body filter by lua will be called before finalizing the request and hence has the right values set. Is Upstream Response time the third parameter to filter? Where did "2" come from? Is there any documentation or code link that I can follow to find out the numbers for other variables as well?