access to Apache environment vars within Spyce
Philip Semanchuk <[email protected]> Fri, 16 Mar 2007 15:06:33 -0400
| Newsgroups | gmane.comp.python.spyce.general |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
I'm using Spyce standalone proxied behind Apache and was wondering how
to get access to Apache environment variables from within Spyce. I came
across this short thread which was not encouraging:
http://sourceforge.net/mailarchive/message.php?msg_id=15336529
I've found a partial solution and I thought I'd post it here for
posterity. Some Googling told me that the standard method for passing
Apache environment variables to a proxy is via mod_headers and the
RequestHeader directive. However, the use of a RewriteRule resets the
environment variables so I have to ensure that the variables I'm
interested in get passed during the rewrite.
So let's say I'm interested in the Apache environment variable
SERVER_PORT. It's not very interesting information, but it's guaranteed
to be available so it's good for example code. My Spyce rewrite rule
looks liks this:
RewriteRule ^(.*\.spy) http://localhost:8000$1
[p,E=MY_CUSTOM_VARIABLE:%{SERVER_PORT}]
Then I use this RequestHeader rule:
RequestHeader add X-MyCustomHeader %{MY_CUSTOM_VARIABLE}e
Then within Spyce, I can then get the variable like this:
<p>custom header: [[=request.getHeader("X-MyCustomHeader")]]</p>
There's a few problems with this method. You have to be careful that
what you pass is a valid header. You have to ensure that you don't step
on any existing headers or allow an opportunity for a hostile user to
pass fake headers to Spyce. (You should probably consider using
"RequestHeader unset X-MyCustomHeader" before adding that header.) Last
but not least, I was unable to get access to all of the environment
variables I wanted to get to via this process. For some reason,
REMOTE_USER just won't appear even if I use the LA-U syntax specified
in the mod_rewrite documentation. As I said, this is only a partial
solution -- as it turns out I've found another way to solve the problem
that I was trying to solve with this method, so I don't need to develop
it any further. I hope it's a useful starting point for someone else.
Cheers
Philip
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV