I am using nginx as a reverse proxy. I am trying to read a custom header set on the client, so I can update a variable with the value of that header.
I set the header in an XHR request similar to xhr.setRequestHeader(‘X-My-Custom-Variable', "1"); xhr.setRequestHeader(‘X-My-Second-Custom-Variable’, 'some-value');
From the docs, I see that I can achieve this on nginx with:
if ($http_x_my_custom_variable = ‘1’) {
set $variable $http_x_my_second_custom_variable;
}
However, this doesn’t work when I run it, $variable is not set.
I have also tried using nginx map keyword like so:
map $http_x_my_custom_variable $variable {
default “”;
“1” $http_x_my_second_custom_variable;
}
and still nothing happens.
I have also confirmed that both headers are set to what I expect on the backend Django server.
Note: My actual header names looks more like: X-ABM-ZHR-XAVIER. I only state this just incase it might have something to do with the structure of the header name. Although I have also tried different permutations of header names just in case.