Christopher Schultz wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Maciej
On 6/24/2009 10:15 AM, Maciej Matecki wrote:
I've got the big problem with forward REMOTE_HOST from Apache to
Tomcat. On the Apache side everything works ok. I've tested it with
PHP script and it simply works. But on the Tomcat side REMOTE_USER
header value is not available.
Apart from what Chris wrote :
do not confuse cgi-bin environment variables, with HTTP Request headers.
As far as I know, all Apache-Tomcat connectors will forward to Tomcat,
all the HTTP headers which they received in the request (which comes
from the browser).
But REMOTE_HOST is /not/ a HTTP Request header received from the
browser. The browser never sends that.
Apache itself detects where the request comes from, and then /creates/
this environment value REMOTE_HOST (and others), in the environment of
the process in which it runs the cgi-bin script.
That is why you "see" it in a PHP script running under Apache.
Apache, or the Apache-Tomcat connector, is under no obligation to do the
same when it passes a request to Tomcat (for one, it would be difficult
to do, because Tomcat is another independent process, whose environment
Apache does not control).
So, what you really want to do here, is
- get some internal value which Apache knows (the IP address from which
the request is coming),
- "translate" this into a /new/ HTTP header REMOTE_HOST,
- and /add/ this HTTP header to the request, before you forward the
request to Tomcat.
Alternatively, you can try to set this IP address into an "Apache
environment variable", using for instance SetEnvIf :
SetEnvIf Remote_Addr "^(.*)$" remote_addr=$1
mod_jk would then normally forward it to Tomcat as a "request attribute"
(I think there is still something to do for that to happen).
Then at the Tomcat level, you use a servlet filter to pick up this
request attribute, and add it as a request header (which would force you
to create a RequestWrapper, because the original Request itself is
immutable).
Now once you are that far anyway, the question would be : why not do
this directly in a Tomcat servlet filter anyway ?
It should also be able to find out the address of the client, and could
create this additional HTTP header.
P.S. I have just checked my favorite tool at
http://www.tuckey.org/urlrewrite,
but unfortunately, adding a HTTP header to the request is not something
it seems able to do.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org