大网数据广告活动
服务器运维问答

Apache Underscore in Header is overwriten

· 52CE 我爱测

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$ ^(.*)$ f…

问题原文

原帖链接 · CasualBen · CC BY-SA 4.0

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 · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-10-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。