[PATCH] add support for getVirtualRoot() or similar to the REQUEST object

Bug #193122 reported by Darryl Dixon
4
Affects Status Importance Assigned to Milestone
Zope 2
Fix Released
Low
Unassigned

Bug Description

Similarly to:
https://bugs.launchpad.net/zope2/+bug/142909 and https://bugs.launchpad.net/zope2/+bug/143217

It is very useful (in fact, necessary in certain scenarios) to have access to the virtual root/path information that is stored in the _script attribute of the REQUEST object.
For example, it may be useful to set a Zope-specific cookie for a domain where multiple systems share the domain name; if Zope lives at:
http://www.example.com/zope
then when setting cookies, you want to be able to specify the path of '/zope' for the cookie. Zope session cookies, for example, would need this ability if you had, eg:
http://www.example.com/zopeA and
http://www.example.com/zopeB
for two different systems both being powered by Zope.

Or, similarly, with ESI setups or similar, you may want to be able to turn out pages that make all links look like: "/url/path" instead of "http://www.example.com/url/path", so that protocol information is not hard-coded in the page.

Exposing access to the _script attribute is relatively trivial, a method similar to the following inside HTTPRequest.py would be sufficient:
def getVirtualRoot(self):
    x = '/' + '/'.join(self._script)
    if x == '/':
        x = ''
        # Could also be set to x = '/.', but that may be misleading...
    return x

Tags: bugday
Revision history for this message
Andreas Jung (ajung) wrote :

The patch requires a unittest.

Changed in zope2:
importance: Undecided → Wishlist
Revision history for this message
Tres Seaver (tseaver) wrote :

I will attach a patch with a cleaner implementation.

Changed in zope2:
importance: Wishlist → Low
status: New → Triaged
tags: added: bugday
Revision history for this message
Tres Seaver (tseaver) wrote :

Unit tests should cover both the case that '_script' empty an that it is not empty.

Revision history for this message
Jens Vagelpohl (dataflake-deactivatedaccount-deactivatedaccount) wrote :

Aded Tres' patch and a test...

Zope 2.12 branch: http://svn.zope.org/?view=rev&rev=115797

Zope trunk: http://svn.zope.org/?view=rev&rev=115798

Changed in zope2:
assignee: nobody → Jens Vagelpohl (dataflake)
milestone: none → 2.12.11
status: Triaged → Fix Committed
Changed in zope2:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.