[Zope] Overriding server's notion of SERVER_NAME, SERVER_PORT, etc.

Skip Montanaro skip@mojam.com (Skip Montanaro)
Wed, 30 Aug 2000 14:00:22 -0500 (CDT)


--9BnfSvwJXZ
Content-Type: text/plain; charset=us-ascii
Content-Description: message body and .signature
Content-Transfer-Encoding: 7bit


In 2.2.1 I can no longer override ZServer's notion of SERVER_NAME,
SERVER_PORT, etc. from the invoking shell environment.  (I am currently
running 2.0.0, so this may well be true of other earlier 2.1.x and 2.2.x
versions.  With a little luck, I may actually be able to upgrade in the next
few days...)

I run ZServer listening to 127.0.0.2, port 9673.  The only thing that talks
directly to it is my front-end Apache server via its proxy module, so I want
any HTML generated to reflect the visible address and port, not ZServer's
hidden address and port.  I was previously able to force these variables to
be what I wanted by simply setting them before running the server:

    SERVER_NAME=dolphin.mojam.com ; export SERVER_NAME
    SERVER_PORT=80 ; export SERVER_PORT
    HTTP_HOST=$SERVER_NAME:$SERVER_PORT ; export HTTP_HOST
    SCRIPT_NAME=/ ; export SCRIPT_NAME

but 2.2.1 ignores these settings.  I made a few simple changes to
ZServer/HTTPServer.py and lib/python/ZPublisher/HTTPRequest.py that use
environment variables as defaults if they're available.  Context diffs are
attached to this msg.  I'd appreciate feedback from those in the know if
these were the correct sort of changes to make or if there is a better
(supported) way to achieve my goal.

Thx,

-- 
Skip Montanaro (skip@mojam.com)
http://www.mojam.com/
http://www.musi-cal.com/



--9BnfSvwJXZ
Content-Type: text/plain
Content-Description: zope changes
Content-Disposition: inline;
	filename="zope-diffs.txt"
Content-Transfer-Encoding: 7bit

diff -rc Zope-2.2.1-src/ZServer/HTTPServer.py Zope-2.2.1-src-new/ZServer/HTTPServer.py
*** Zope-2.2.1-src/ZServer/HTTPServer.py	Tue Jun 27 10:55:14 2000
--- Zope-2.2.1-src-new/ZServer/HTTPServer.py	Wed Aug 30 13:47:12 2000
***************
*** 223,238 ****
          server=request.channel.server
          env = {}
          env['REQUEST_METHOD']=upper(request.command)
!         env['SERVER_PORT']=str(server.port)
!         env['SERVER_NAME']=server.server_name
          env['SERVER_SOFTWARE']=server.SERVER_IDENT
          env['SERVER_PROTOCOL']=request.version
          env['channel.creation_time']=request.channel.creation_time
          if self.uri_base=='/':
!             env['SCRIPT_NAME']=''
!             env['PATH_INFO']='/' + path
          else:
!             env['SCRIPT_NAME'] = self.uri_base
              try:
                  path_info=split(path,self.uri_base[1:],1)[1]
              except:
--- 223,242 ----
          server=request.channel.server
          env = {}
          env['REQUEST_METHOD']=upper(request.command)
!         env['SERVER_PORT']=os.environ.get("SERVER_PORT", str(server.port))
!         env['SERVER_NAME']=os.environ.get("SERVER_NAME", server.server_name)
          env['SERVER_SOFTWARE']=server.SERVER_IDENT
          env['SERVER_PROTOCOL']=request.version
          env['channel.creation_time']=request.channel.creation_time
          if self.uri_base=='/':
!             env['SCRIPT_NAME']=os.environ.get("SCRIPT_NAME", '')
!             if not env['SCRIPT_NAME']:
!                 env['PATH_INFO']='/' + path
!             else:
!                 env['PATH_INFO'] = env['SCRIPT_NAME'] + path
          else:
!             env['SCRIPT_NAME'] = os.environ.get("SCRIPT_NAME",
!                                                 self.uri_base)
              try:
                  path_info=split(path,self.uri_base[1:],1)[1]
              except:
diff -rc Zope-2.2.1-src/lib/python/ZPublisher/HTTPRequest.py Zope-2.2.1-src-new/lib/python/ZPublisher/HTTPRequest.py
*** Zope-2.2.1-src/lib/python/ZPublisher/HTTPRequest.py	Tue Aug 15 15:07:37 2000
--- Zope-2.2.1-src-new/lib/python/ZPublisher/HTTPRequest.py	Wed Aug 30 13:43:05 2000
***************
*** 266,272 ****
          else: b=''
          while b and b[0]=='/': b=b[1:]
  
!         server_url=get_env('SERVER_URL',None)
          if server_url is not None:
               other['SERVER_URL'] = server_url = strip(server_url)
          else:
--- 266,272 ----
          else: b=''
          while b and b[0]=='/': b=b[1:]
  
!         server_url=get_env('SERVER_URL',os.environ.get("SERVER_URL", ""))
          if server_url is not None:
               other['SERVER_URL'] = server_url = strip(server_url)
          else:

--9BnfSvwJXZ--