source: products/vendor/Products.CacheSetup/current/Products/CacheSetup/skins/cache_setup/rewritePurgeUrls.py @ 3296

Last change on this file since 3296 was 3296, checked in by fenix, 12 years ago

Load Products.CacheSetup?-1.2.1 into vendor/Products.CacheSetup?/current.

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1## Script (Python) "rewritePurgeUrls"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=relative_urls,domains
8##title=Custom rewrite of purge url paths
9
10# Rewrite the purge URLs in case the request paths passed to the cache proxy
11# are different than the relative URLs in the Zope virtual host context.
12# We put this here to make it easier to adjust this behavior for custom
13# cache proxy setups.  Two example rewrite behaviors are provided below.
14#
15# Example 1: Legacy CacheFu 1.0 Squid-Apache config
16#
17# For those who haven't yet updated their old-style squid-apache configs.
18# The old default "squid_behind_apache" setup assumed URLs passed
19# to Squid from Apache are of the form:
20# [squid_url]/[protocol]/[host]/[port]/[path]
21#
22# Example 2: VirtualHostMonster-style URLs in the 'inside-out' configuration
23#
24# For those using the special _vh_ option for VHM URLs where the root url of
25# the plone site is configured as a subfolder of the domain.  The URLs passed
26# to the proxy cache server are of the form:
27# [squid_url]/VirtualHostBase/[protocol]/[host]:[port]/[zopepath]  \
28#            /VirtualHostRoot/_v_[subfolder]/[path]
29# See http://plone.org/documentation/tutorial/plone-apache/vhm for details
30
31
32# Example 1
33def rewrite_legacy(relative_urls, domains):
34    prefixes = []
35    for d in domains:
36        protocol = d[0]
37        host = d[1]
38        split_host = host.split(':')
39        host = split_host[0]
40        port = split_host[1]
41        prefixes.append('%s/%s/%s/' % (protocol, host, port))
42    relative_urls = [prefix+url for prefix in prefixes for url in relative_urls]
43    return relative_urls
44
45
46# Example 2
47def rewrite_insideout(relative_urls, domains):
48    subfolder = 'folder/subfolder'  # change this to match your config.
49    from Products.CMFCore.utils import getToolByName
50    url_tool = getToolByName(context, 'portal_url')
51    portal_path = '/'.join(url_tool.getPortalObject().getPhysicalPath())
52    prefixes = []
53    for d in domains:
54        protocol = d[0]
55        host = d[1]
56        split_host = host.split(':')
57        host = split_host[0]
58        port = split_host[1]
59        prefixes.append('VirtualHostBase/%s/%s:%s%s/VirtualHostRoot/_vh_%s' % (protocol, host, port, portal_path, subfolder))
60    relative_urls = [prefix+url for prefix in prefixes for url in relative_urls]
61    return relative_urls
62
63
64# The default case is example 1
65return rewrite_legacy(relative_urls, domains)
66
67
Note: See TracBrowser for help on using the repository browser.