summaryrefslogtreecommitdiff
path: root/cherrypy/_cphttptools.py
diff options
context:
space:
mode:
Diffstat (limited to 'cherrypy/_cphttptools.py')
-rw-r--r--cherrypy/_cphttptools.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/cherrypy/_cphttptools.py b/cherrypy/_cphttptools.py
index 4b4f6503..64403805 100644
--- a/cherrypy/_cphttptools.py
+++ b/cherrypy/_cphttptools.py
@@ -520,19 +520,20 @@ def mapPathToObject(path = None):
raise IndexRedirect(newUrl)
return candidate, objectPathList, virtualPathList
-
-def canonicalizeUrl(newUrl):
- if not newUrl.startswith('http://') and not newUrl.startswith('https://'):
- # If newUrl is not canonical, we must make it canonical
- if newUrl[0] == '/':
+
+def canonicalizeUrl(url):
+ """ Canonicalize a URL. The URL might be relative, absolute or canonical """
+ if not url.startswith('http://') and not url.startswith('https://'):
+ # If url is not canonical, we must make it canonical
+ if url[0] == '/':
# URL was absolute: we just add the request.base in front of it
- newUrl = cpg.request.base + newUrl
+ url = cpg.request.base + url
else:
# URL was relative
if cpg.request.browserUrl == cpg.request.base:
# browserUrl is request.base
- newUrl = cpg.request.base + '/' + newUrl
+ url = cpg.request.base + '/' + url
else:
i = cpg.request.browserUrl.rfind('/')
- newUrl = cpg.request.browserUrl[:i+1] + newUrl
- return newUrl
+ url = cpg.request.browserUrl[:i+1] + url
+ return url