[Zope] ANN: Serving PHP/Perl from Zope update

Bill Welch bill@carbonecho.com
Wed, 6 Sep 2000 19:47:46 +0000 (GMT)


Got authorization to work!

First, another patch to Client.py to raise 'Unauthorized' when 401 is
returned by PHP/Perl:

after line that starts with

   if ec==200

add

   if ec==401:
      raise 'Unauthorized'

Second, numerous changes to the external method that makes the request and
receives the response. Here's the whole thing

def ServePHP(self):
    req = self.REQUEST
    (username, password) = req._authUserPW()

    headers = {}
    if req.environ.has_key('HTTP_COOKIE'):
        headers = {'Cookie' : req.environ['HTTP_COOKIE']}
    if req.environ.has_key('HTTP_USER_AGENT'):
        headers = {'User-Agent' : req.environ['HTTP_USER_AGENT']}
            
    if req.environ['REQUEST_METHOD'] == 'POST':
        rTuple =  apply(Client.call, (req['phpScript'], username, password, headers), req.form)
    else:
        rTuple = Client.call(req['phpScript'], username, password, headers)
                
    resp = req['RESPONSE']
    # the first element of the return tuple is dervied from rfc822
    for cookie in rTuple[0].getallmatchingheaders('Set-Cookie'):
        cookie = cookie[:-1] # remove \n - is there an idiom for this?
        apply(resp.setHeader, split(cookie, ':', 1))
            
    # not a particularly strong test, maybe Client should pass back status
    if rTuple[0].has_key('location'):
        # override base so that relative references work
        resp.base = rTuple[0]['location']
        raise 'Redirect', resp.base
            
    #override base so that relative references work
    resp.base = 'http://www.carbonecho.com:10080/forum/' + req['origScript']
            
    return rTuple[1]