Re: [users@httpd] Rewriting headers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On May 20, 2005, at 06:04 AM, Alexander Mueller wrote:
I am looking for a way to rewrite HTTP headers of requests passing through in proxy mode (mod_proxy). This works in connection with mod_headers, however it only allows basic manipulation (adding, removing, changing). I would need a way to use values of existing headers and incorporate them into newly added ones.

Is there maybe already some solution/module which provides such functionality or would it require a modification of mod_headers? Thanks for any insight.

Yes. This is what the mod_rewrite module is for. What you need to do is not use mod_proxy directly (i.e. ProxyPass), but do your reverse proxy handling through mod_rewrite (the [P] flag for RewriteRule). That way, you can use mod_rewrite to grab an HTTP header value and place it into an environment variable. That would allow you to access that value via mod_headers, before you go back to mod_rewrite to do the reverse proxy call.

Here's an example...

    RewriteEngine on

# Get the custom header value and store in a temporary environment variable
    RewriteCond %{HTTP:X-Custom-Header-Name} (.*)
    RewriteRule .* - [E=FOO_HEADER:%1]

# We need the FOO_HEADER on the proxy side of things, so we grab the value from the temp # variable and add it as a new HTTP header for the upcoming proxy request
    RequestHeader add X-My-FOO %{FOO_HEADER}e

    # Send our request to the proxy location
    RewriteRule ^/(.*)$ http://127.0.0.1:8080/$1 [P,L]

-Brian


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
  "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux