Changeset 124
- Timestamp:
- 01/10/05 12:01:18
- Files:
-
- trunk/cherrypy/_cphttptools.py (modified) (1 diff)
- trunk/cherrypy/lib/httptools.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cphttptools.py
r122 r124 521 521 522 522 return candidate, objectPathList, virtualPathList 523 524 def canonicalizeUrl(newUrl): 525 if not newUrl.startswith('http://') and not newUrl.startswith('https://'): 526 # If newUrl is not canonical, we must make it canonical 527 if newUrl[0] == '/': 523 524 def canonicalizeUrl(url): 525 """ Canonicalize a URL. The URL might be relative, absolute or canonical """ 526 if not url.startswith('http://') and not url.startswith('https://'): 527 # If url is not canonical, we must make it canonical 528 if url[0] == '/': 528 529 # URL was absolute: we just add the request.base in front of it 529 newUrl = cpg.request.base + newUrl530 url = cpg.request.base + url 530 531 else: 531 532 # URL was relative 532 533 if cpg.request.browserUrl == cpg.request.base: 533 534 # browserUrl is request.base 534 newUrl = cpg.request.base + '/' + newUrl535 url = cpg.request.base + '/' + url 535 536 else: 536 537 i = cpg.request.browserUrl.rfind('/') 537 newUrl = cpg.request.browserUrl[:i+1] + newUrl538 return newUrl538 url = cpg.request.browserUrl[:i+1] + url 539 return url trunk/cherrypy/lib/httptools.py
r119 r124 33 33 from cherrypy import cpg 34 34 35 def redirect(newUrl): 36 """ Sends a redirect to the browser """ 37 38 if not newUrl.startswith('http://') and not newUrl.startswith('https://'): 39 # If newUrl is not canonical, we must make it canonical 40 if newUrl.startswith('/'): 41 # newUrl was absolute: 42 # we just add request.base in front of it 43 newUrl = cpg.request.base + newUrl 35 def canonicalizeUrl(url): 36 """ Canonicalize a URL. The URL might be relative, absolute or canonical """ 37 if not url.startswith('http://') and not url.startswith('https://'): 38 # If url is not canonical, we must make it canonical 39 if url[0] == '/': 40 # URL was absolute: we just add the request.base in front of it 41 url = cpg.request.base + url 44 42 else: 45 # newUrl was relative: 46 # we remove the last bit from browserUrl and add newUrl to it 47 i = cpg.request.browserUrl.rfind('/') 48 newUrl = cpg.request.browserUrl[:i+1] + newUrl 43 # URL was relative 44 if cpg.request.browserUrl == cpg.request.base: 45 # browserUrl is request.base 46 url = cpg.request.base + '/' + url 47 else: 48 i = cpg.request.browserUrl.rfind('/') 49 url = cpg.request.browserUrl[:i+1] + url 50 return url 51 52 def redirect(url): 53 """ Sends a redirect to the browser (after canonicalizing the URL) """ 49 54 cpg.response.headerMap['Status'] = 302 50 cpg.response.headerMap['Location'] = newUrl55 cpg.response.headerMap['Location'] = canonicalizeUrl(url) 51 56 return ""

