[mod_python] Detecting http vs. https

Niklas Aldergren niklas at chimney.se
Fri Sep 17 02:15:31 EDT 2004


On 17 sep 2004, at 00.59, Nick wrote:

> The HTTPS variable will be set in the environment.
>
> Nick
>
> Adrian Holovaty wrote:
>> Hey everybody,
>> What's the easiest and most reliable way for me to detect if a 
>> request has come in via https vs. http?
>> It'd be best if I didn't have to parse any of the request attributes 
>> manually.
>> Thanks,
>> Adrian

In Apache 2, mod_ssl can be made to set all sorts of fancy environment 
variables,
like HTTPS, etc. But, seeing as the interpreter is embedded in the 
actual
server process I'm guessing this can't actually be set since a new 
process is
never created. Try looking at os.environ -- what I find there is the 
environment
for the server process.

A strikingly unreliable way to detect http/https would be to look at 
what
local port the request came in on, either at req.server.port or 
req.connection.local_addr.

Otherwise, it's bound to be in the Apache internals somewhere.

/Niklas



More information about the Mod_python mailing list