2

I am testing a web application that is hosted in production behind SiteMinder, which authenticates the user and adds an HTTP header to each request that identifies that user.

The application does not work if the header is not present and I am trying to test it using Watir and Webdriver. This combination drives a real browser (e.g. Firefox) locally so I am not able to insert HTTP headers easily via WebDriver. Our local test environment does not have SiteMinder so I need a way to insert the headers.

I have set up Apache 2 as a reverse proxy and want to translate a request like:

GET /[email protected]/application/index.html

into:

GET /application/index.html
SM_USER: [email protected]

Our servers are all Solaris 10 and I am currently using Apache/2.0.63 as installed with the OS (we are not using it for anything else).

The closest I have got is to use SetEnvIf and mod_rewrite:

SetEnvIf Request_URI "SM_USER=([^/]+)" HTTP_SM_USER=$1
RewriteEngine on
RewriteRule ^/.+(/application/.+)$ http://apphost:9090$1 [P]

But the header is not being set. It appears that the value of Request_URI is being rewritten before the SetEnvIf directive is being executed, so SM_USER is no longer in the URI.

If I am right about this, is it possible to change the order of execution so SetEnvIf gets the original URI? Or do I need a different approach?

1 Answer 1

1

My colleague came up with a solution. I had made the mistake of assuming that using SetEnvIf by itself was sufficient. This is now working for us:

RewriteEngine on
# Anything ending with /application/.+ goes to http://apphost:9090
RewriteRule ^/.+(/application/.+)$ http://apphost:9090$1 [P]
# Match SM_USER= in the URI and set an env var with its value.
SetEnvIf Request_URI "SM_USER=([^/]+)" SM_USER=$1
# If the env var is set, put the value into a request header.
RequestHeader set SM_USER "%{SM_USER}e" env=SM_USER

This URI is proxied to http://apphost:9090/application/index.html with the HTTP header SM_USER set to [email protected]:

/[email protected]/application/index.html
1
  • As someone who likes using Apache reverse proxy regularly, I appreciate the question & answer here. Very helpful. Nov 13, 2013 at 21:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .