Apache Underscore in Header Overwritten

.htaccessapache-2.4http-headers

I've a service which sets the header x-user_type. Since Apache2.4.33 cannot use this, i'll transform this with the following in a .htaccess:

<IfModule mod_headers.c>
    <IfModule mod_setenvif.c>
        SetEnvIfNoCase ^x.user.type$ ^(.*)$ fix_x-user_type=$1
        RequestHeader set x-user-type %{fix_x-user_type}e env=fix_x-user_type
    </IfModule>
</IfModule>

But if i supply x-user-type within a request then the value for x-user-type in the response is overwritten

Examples:

  • Nothing supplied -> x-user-type = application (This is set by the service)
  • x-user_type = test -> x-user-type = application (This is ok, since it is set by the service)
  • x-user-type = test -> x-user-type = test (This should be application as well)

I think this is an apache configuration issue. Can someone help me solve this?

Best Answer

Fixed my own Problem with this: https://serverfault.com/a/900745/490242

Quote:

The value of a RequestHeader set supports expressions, and expressions include the req (or http) function, which gives you the value of request headers. So this one directive should do what you want:

RequestHeader set X-CAS-email-primary "expr=%{req:X-CAS-email_primary}" You have to dig deep into the documentation to find this kind of thing, but it's there.

Not sure why your configuration didn't work, but I guess the SetEnvIfNoCase is evaluated after the RequestHeader. The docs don't make it easy to figure that out.

Seems like SetEnvIfNoCase was my problem too.