Apache – How to Edit HTTP Headers

apache-2.4http-headerslinuxmod-proxyreverse-proxy

I have setup with apache (apache 2.4, redhat 7.6) reverse proxy in front of the JVM.
Apache has basic authentication setup on it.

The problem is that Apache header with info about basic authentication is being sent to the JVM itself. I would need a way to edit the apache header before its sent to the JVM so instead of

Auhorization: Basic some_text_goes_here, Bearer  some_text_goes_here

I get only this sent to the JVM

Auhorization: Bearer  some_text_goes_here

Is there a way to strip the Basic authentication information from the header before its sent to the JVM ?

Best Answer

You can use the RequestHeader directive to replace the header before it is sent to the backend server.

RequestHeader set Auhorization "Bearer some_text_goes_here"

If you want to actually remove part of the header string, you can use edit along with a regular expression.

RequestHeader edit Auhorization "Basic[^,]+, " ""

The regex is looks for the string "Basic", followed by one ore more characters that are not a comma, followed by a comma and a space and replaces it with an empty string. This is however just a guess, since we don't know what exactly is in your request header you will have to figure the correct regular expression for this yourself.