Add a custom header to ProxyPass requests

Ok I got it.

First of all, the script that is executed and that is used to get the value to insert in the header. I created this as /opt/apache/debug.sh:

#!/bin/bash

#this script just loops forever and outputs a random string
#every time it receives something on stdin

while read
do
        cat /dev/urandom|head -c12|base64
done

Apache config:

<VirtualHost *:80>
        ServerName light.nik

        RewriteEngine On

        RewriteMap doheader prg:/opt/apache/debug.sh
        RewriteRule (.*) - [E=customheader:${doheader:},P]

        RequestHeader set customheader %{customheader}e

        ProxyPass / http://localhost:8080/
        ProxyPassReverse / http://localhost:8080/
</VirtualHost>

The backend service running on http://localhost:8080/ receives the customheader with the value from the script.

The Apache documentation about using external program is here.