2

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?

CasualBen
  • 161
  • 9

1 Answers1

4

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.

CasualBen
  • 161
  • 9
  • If someone has a similar problem where they want/need to support both cases of the header (e.g. `X-CAS-email-primary` and `X-CAS-email_primary`), the [RequestHeader directive](http://httpd.apache.org/docs/current/mod/mod_headers.html#requestheader) also has the method `setifempty` which won't overwrite the header if it is already set (available in 2.4.7 and later). – tharkay May 19 '20 at 13:02