Changeset 156
- Timestamp:
- 04/24/05 11:04:26
- Files:
-
- trunk/CHANGELOG.txt (modified) (1 diff)
- trunk/cherrypy/_cphttptools.py (modified) (3 diffs)
- trunk/cherrypy/lib/httptools.py (modified) (1 diff)
- trunk/cherrypy/test/test.py (modified) (1 diff)
- trunk/cherrypy/test/testObjectMapping.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/CHANGELOG.txt
r135 r156 6 6 * Added DecodingFilter (Remi) 7 7 * Added form module (port from CP1 Form.cpy) (Remi) 8 * Improved the way static files are being served (Remi) 8 9 9 10 2004/12-29: trunk/cherrypy/_cphttptools.py
r155 r156 28 28 29 29 import cpg, urllib, sys, time, traceback, types, StringIO, cgi, os 30 import mimetypes, sha, random, string, _cputil, cperror, Cookie 30 import mimetypes, sha, random, string, _cputil, cperror, Cookie, urlparse 31 31 from lib.filter import basefilter 32 32 … … 385 385 # For an IndexRedirect, we don't go through the regular 386 386 # mechanism: we return the redirect immediately 387 newUrl = canonicalizeUrl(inst.args[0])387 newUrl = urlparse.urljoin(cpg.request.base, inst.args[0]) 388 388 wfile.write('%s 302\r\n' % (cpg.response.headerMap['protocolVersion'])) 389 389 cpg.response.headerMap['Location'] = newUrl … … 535 535 536 536 return candidate, objectPathList, virtualPathList 537 538 def canonicalizeUrl(url):539 """ Canonicalize a URL. The URL might be relative, absolute or canonical """540 if not url.startswith('http://') and not url.startswith('https://'):541 # If url is not canonical, we must make it canonical542 if url[0] == '/':543 # URL was absolute: we just add the request.base in front of it544 url = cpg.request.base + url545 else:546 # URL was relative547 if cpg.request.browserUrl == cpg.request.base:548 # browserUrl is request.base549 url = cpg.request.base + '/' + url550 else:551 i = cpg.request.browserUrl.rfind('/')552 url = cpg.request.browserUrl[:i+1] + url553 return urltrunk/cherrypy/lib/httptools.py
r124 r156 32 32 33 33 from cherrypy import cpg 34 import urlparse 34 35 35 36 def canonicalizeUrl(url): 36 37 """ 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 42 else: 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 38 return urlparse.urljoin(cpg.request.base, url) 51 39 52 40 def redirect(url): trunk/cherrypy/test/test.py
r108 r156 167 167 print "**** THE ABOVE TESTS FAILED" 168 168 print 169 print "**** Some errors occured: please add a ticket in our Trac system (http://trac.cherrypy.org/ cgi-bin/trac.cgi/newticket) with the output of this test script"169 print "**** Some errors occured: please add a ticket in our Trac system (http://trac.cherrypy.org/newticket) with the output of this test script" 170 170 171 171 else: trunk/cherrypy/test/testObjectMapping.py
r122 r156 31 31 code = """ 32 32 from cherrypy import cpg 33 from cherrypy.lib import httptools 33 34 class Root: 34 35 def index(self, name="world"): … … 44 45 return repr(p) 45 46 extra.exposed = True 47 def redirect(self): 48 return httptools.redirect('dir1/') 49 redirect.exposed = True 46 50 def notExposed(self): 47 51 return "not exposed" … … 88 92 " and cpg.response.headerMap['Location'] == 'http://127.0.0.1/dir1/dir2/'"), 89 93 ("/dir1/dir2/dir3/dir4/index", '''cpg.response.body == "default for dir1, param is:('dir2', 'dir3', 'dir4', 'index')"'''), 94 ("/redirect", "cpg.response.headerMap['Status'] == 302" + 95 " and cpg.response.headerMap['Location'] == 'http://127.0.0.1/dir1/'"), 90 96 ] 91 97

