[Zope-dev] ZServer/start.py suggestion

skip@mojam.com (Skip Montanaro) skip@mojam.com (Skip Montanaro)
Wed, 21 Apr 1999 13:30:03 -0400


I finally figured out today how to override environment variables in
ZServer.  By passing an "env" argument when instantiating the zhttp_handler
class, you can pass in environment variables when starting ZServer:

    env = {}
    for key in os.environ.keys():
	if key[0:5] == "HTTP_": env[key] = os.environ[key]
	if key[0:7] == "SCRIPT_": env[key] = os.environ[key]
	if key[0:7] == "SERVER_": env[key] = os.environ[key]
	pass

    zh = zhttp_handler(module=MODULE, uri_base="", env=env)

Since it isn't mentioned in the Zope documentation (at least I couldn't find
it), I suggest it be added to start.py with a descriptive comment:

    # If you are running ZServer behind a proxy server you may want to
    # override a number of REQUEST variables from the environment to allow
    # URL* and BASE* variables to be set to reflect the proxy's address.  To 
    # enable this capability, uncomment and modify the for loop below as
    # desired.
    env = {}
    #for key in os.environ.keys():
    #	if key[0:5] == "HTTP_": env[key] = os.environ[key]
    #	if key[0:7] == "SCRIPT_": env[key] = os.environ[key]
    #	if key[0:7] == "SERVER_": env[key] = os.environ[key]
    #	pass

    zh = zhttp_handler(module=MODULE, uri_base="", env=env)

Skip Montanaro	| Mojam: "Uniting the World of Music" http://www.mojam.com/
skip@mojam.com  | Musi-Cal: http://www.musi-cal.com/
518-372-5583