[Zope-dev] PROPOSAL: Site objects

Evan Simpson evan@tokenexchange.com
Tue, 21 Sep 1999 14:46:07 -0500


I had some further thoughts on rewriting/vhosting within Zope.  I'd like to
provide fairly powerful rules, on the order of those provided by Apache.  My
first impulse was to design AccessRule objects, which could be combined and
nested to implement the rules, but then I changed my mind.  Zope already has
fairly powerful logic available through its Methods. If Request objects are
given the setSite method you mention, and regular expressions are made
available, then ordinary DTML- or Python- Methods could be used to implement
rewrite rules.

Perhaps it would be enough to single out an object to be called at the start
of each request.  The Request object would be passed into it, containing the
environment/HTTP variables and other stuff available at this point.  There
would be no PARENTS in the Request, and no namespace.  All the method would
do is examine the variables and possibly call a method of the Request to
change PATH_INFO.  Example:

<dtml-if "REQUEST['HTTP_HOST']=='site1.com'">
    <dtml-call "REQUEST.setPath('/here/there/site1/'+REQUEST['PATH_INFO'])">
<dtml-elif "REQUEST['HTTP_HOST']=='site2.com">
    <dtml-call
"REQUEST.setPath('/another/place/site2/'+REQUEST['PATH_INFO'])">
</dtml-if>

or with a PythonMethod (my personal preference <wink>):

global vhosts
if not globals().has_key('vhosts'):
  vhosts = {'site1.com': '/here/there/site1/', 'site2.com':
'/another/place/site2'}
new_path = vhosts.get(REQUEST['HTTP_HOST'], None)
if new_path is not None:
  REQUEST.setPath(new_path + REQUEST['PATH_INFO']

In either case, there could be SiteRoot objects in the resulting paths which
would fix up the logical URLs, once traversed.  Also, providing access in
the rewriter to ts_regex or re (through a temporary attribute of REQUEST?)
would be very cool.

----- Original Message -----
From: Jim Fulton <jim@digicool.com>
>
>   http://www.zope.org/Members/jim/SiteObjectProposal
>
> Comments?