I'm using apache as a frontend http proxy. I need to send a header with a value from a specific environment variable to all proxied request. Like this:
RequestHeader set myheader %{FOO}e
The issue is that the value from the env variable FOO
must be base64 encoded. Is it possible to b64-encode that header value on the fly?
mod_rewrite? subrequest? a custom module? ...
Btw, the env variable is created by another apache module, which I cannot fix unfortunately.
I figured it out. Using mod_rewrite to read/write stdin/stdout from an external program like this:
ProxyRequests on
RewriteEngine on
# 1
RewriteMap base64map "prg:/bin/b64e"
# 2
RewriteRule .* - [E=WIC:${base64map:%{QUERY_STRING}},NE]
# 3
RequestHeader set x-b64encoded "%{ENV:WIC}e"
# 4
RewriteRule ^proxy/.*$ http://localhost:9999 [P]
base64map
which runs the executable (/bin/b64e
) which reads stdin and encodes on stdout.
The executable is loaded when apache starts and you have to make a loop reading from the stdin and passing it through the / bin / base64 for it to work wellbase64map
. The output is used to set the apache variable WIC
to the encoded value.x-b64encoded
is created from the value in WIC
To correctly read the WIC variable we had to change the syntax to ENV: WICIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With