Welcome! Log In Create A New Profile

Advanced

Re: Variable “set” in map with an Header Value was lost when we delete the header.

Maxim Dounin
January 12, 2022 01:38PM
Hello!

On Wed, Jan 12, 2022 at 12:44:34PM -0500, podzol33 wrote:

> We have an responseHeader with technical information sent by the upstream
> server tomcat.
> We want to log this information in nginx and delete the header to avoid to
> be visible in the response Header to the client.
>
> log_format formatjson escape=json '{
> '"tomcat_container_id": "$TOMCAT_CONTAINER_ID" }';
>
> Nginx.conf in http {
> map $sent_http_Container_Id $TOMCAT_CONTAINER_ID {
> default $sent_http_Container_Id;
> }
> more_clear_headers 'Container-Id';
>
> When I do this, my log tomcat_container_id is empty.
> If I comment the more_clear_header command line, I have my log fill with the
> right value but the header is also sent to the client.
> So I don’t understand why my $TOMCAT_CONTAINER_ID Is clear when I delete the
> header and not clear if I don’t.

Maps are evaluated when you access resulting variable, so it is
expected that the map result will be empty if there are no
$sent_http_container_id during map evaluation, that is, at
logging. Overall, your construct is no different from using
$sent_http_container_id in the log format directly.

As far as I understand what you are trying to do, proper solution
would be to void both 3rd-party more_clear_headers and map, and
instead use proxy_hide_header[1] to hide the header, and use the
$upstream_http_container_id[2] variable for logging the original
upstream response header. Something like this:

log_format formatjson escape=json '{
'"tomcat_container_id": "$upstream_http_container_id" }';
proxy_hide_header Container-Id;

Hope this helps.

[1] http://nginx.org/r/proxy_hide_header
[2] http://nginx.org/r/$upstream_http_

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-leave@nginx.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
Subject Author Posted

Variable “set” in map with an Header Value was lost when we delete the header.

podzol33 January 12, 2022 12:44PM

RE: Variable “set” in map with an Header Value was lost when we delete the header.

Reinis Rozitis January 12, 2022 01:30PM

Re: Variable “set” in map with an Header Value was lost when we delete the header.

Maxim Dounin January 12, 2022 01:38PM

Re: Variable “set” in map with an Header Value was lost when we delete the header.

podzol33 January 14, 2022 10:10AM

proxy_hide header not working

arunr039 August 23, 2022 03:11AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 227
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