Hi there,
I'm trying (unsuccessfully) to read an upstream/sent response header and set an additional one based on some regex.
Let's say I want to check if the site served is WordPress. WordPress will usually output a link header like this:
link: https://www.domain.com/wp-json/; rel="https://api.w.org/", https://www.domain.com/; rel=shortlink
So if I did this:
[code]
set $IS_WORDPRESS "false";
# Now lookup "wp-json" in the (response) link header
if ($sent_http_link ~* "wp-json") {
set $IS_WORDPRESS "true";
}
add_header X-Sent-Header "$sent_http_link";
add_header X-Is-WordPress $IS_WORDPRESS;
[/code]
You'd probably expect to see 2 headers output here, but in reality you only get 1:
x-is-wordpress: false
x-sent-header is empty and is not output. Additionally, the regex does not match at all, that's why x-is-wordpress returns false.
Now dig this. If I comment out the if block, the "$sent_http_link" value is output just fine
x-sent-header: https://www.domain.com/wp-json/; rel="https://api.w.org/", https://www.domain.com/; rel=shortlink
x-is-wordpress: false
It's as if the sent header is nulled if I just call it!
Is this expected behaviour? Could there be another way to do this?
The same happens if I use $upstream_http_X as this is a proxy setup (Nginx to Apache).
---
Maker of Engintron - https://engintron.com
The easy way to integrate Nginx on cPanel as a reverse caching proxy that actually works for any type of website (even forums or e-shops).