Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1919: wsgi.patch

File wsgi.patch, 4.2 KB (added by chrisz, 4 years ago)

Patch to make TG 1.0 use SCRIPT_NAME in addition to server.webpath

  • controllers.py

     
    501501    """Computes URLs. 
    502502 
    503503    tgpath can be a list or a string. If the path is absolute (starts 
    504     with a "/"), the server.webpath and the approot of the application 
    505     are prepended to the path. In order for the approot to be 
    506     detected properly, the root object should extend 
     504    with a "/"), the server.webpath, SCRIPT_NAME and the approot of the 
     505    application are prepended to the path. In order for the approot to 
     506    be detected properly, the root object should extend 
    507507    controllers.RootController. 
    508508 
    509509    Query parameters for the URL can be passed in as a dictionary in 
     
    516516    if not isinstance(tgpath, basestring): 
    517517        tgpath = "/".join(list(tgpath)) 
    518518    if tgpath.startswith("/"): 
     519        webpath = config.get('server.webpath', '').rstrip('/') 
    519520        if tg_util.request_available(): 
    520521            check_app_root() 
    521522            tgpath = request.app_root + tgpath 
    522         result = config.get("server.webpath", "") + tgpath 
    523     else: 
    524         result = tgpath 
     523            try: 
     524                webpath += request.wsgi_environ['SCRIPT_NAME'].rstrip('/') 
     525            except (AttributeError, KeyError): 
     526                pass 
     527        tgpath = webpath + tgpath 
    525528    if tgparams is None: 
    526529        tgparams = kw 
    527530    else: 
     
    545548                v = v.encode("utf8") 
    546549            args.append("%s=%s" % (k, urllib.quote(str(v)))) 
    547550    if args: 
    548         result += "?" + "&".join(args) 
    549     return result 
     551        tgpath += "?" + "&".join(args) 
     552    return tgpath 
    550553 
    551554 
    552555def check_app_root(): 
  • startup.py

     
    7878 
    7979cherrypy.lib.autoreload.reloader_thread = reloader_thread 
    8080 
    81 webpath = "" 
     81webpath = '' 
    8282 
    8383DNS_SD_PID = None 
    8484 
     
    129129    maps to the root object "/". 
    130130    """ 
    131131 
     132    def __init__(self, webpath=''): 
     133        webpath = webpath.rstrip('/') 
     134        if webpath and not webpath.startswith('/'): 
     135             webpath = '/' + webpath 
     136        self.webpath = webpath 
     137 
    132138    def on_start_resource(self): 
    133         prefix = config.get('server.webpath', False) 
    134         if prefix: 
     139        webpath = self.webpath 
     140        try: 
     141            webpath += cherrypy.request.wsgi_environ['SCRIPT_NAME'].rstrip('/') 
     142        except (AttributeError, KeyError): 
     143            pass 
     144        if webpath: 
    135145            path = cherrypy.request.object_path 
    136             if path == prefix: 
     146            if path == webpath: 
    137147                cherrypy.request.object_path = '/' 
    138             elif path.startswith(prefix): 
    139                 cherrypy.request.object_path = path[len(prefix):] 
     148            elif path.startswith(webpath): 
     149                cherrypy.request.object_path = path[len(webpath):] 
    140150            else: 
    141151                raise cherrypy.NotFound(path) 
    142152 
     
    182192    view.load_engines() 
    183193    view.loadBaseTemplates() 
    184194    global webpath 
    185     webpath = config.get("server.webpath", "") 
     195    webpath = config.get('server.webpath', '') 
    186196 
    187     if hasattr(cherrypy, "root") and cherrypy.root: 
    188         if not hasattr(cherrypy.root, "_cp_filters"): 
     197    if hasattr(cherrypy, 'root') and cherrypy.root: 
     198        if not hasattr(cherrypy.root, '_cp_filters'): 
    189199            cherrypy.root._cp_filters= [] 
    190         morefilters = [EndTransactionsFilter(), 
    191                        NestedVariablesFilter()] 
    192         if webpath: 
    193             morefilters.insert(0, VirtualPathFilter()) 
     200        morefilters = [EndTransactionsFilter(), NestedVariablesFilter()] 
     201        morefilters.insert(0, VirtualPathFilter(webpath)) 
    194202        cherrypy.root._cp_filters.extend(morefilters) 
    195203 
    196     if webpath.startswith("/"): 
    197         webpath = webpath[1:] 
    198     if webpath and not webpath.endswith("/"): 
    199         webpath = webpath + "/" 
     204    webpath = webpath.lstrip('/') 
     205    if webpath and not webpath.endswith('/'): 
     206        webpath += '/' 
     207 
    200208    isdev = config.get('server.environment') == 'development' 
    201209    if not config.get("tg.new_style_logging"): 
    202210        if config.get('server.log_to_screen'):