Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 156

Show
Ignore:
Timestamp:
04/24/05 11:04:26
Author:
rdelon
Message:

Fixed ticket #123; now using urlparse.urljoin for concatenating urls; added a test for httptools.redirect()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/CHANGELOG.txt

    r135 r156  
    66    * Added DecodingFilter (Remi) 
    77    * Added form module (port from CP1 Form.cpy) (Remi) 
     8    * Improved the way static files are being served (Remi) 
    89 
    9102004/12-29: 
  • trunk/cherrypy/_cphttptools.py

    r155 r156  
    2828 
    2929import cpg, urllib, sys, time, traceback, types, StringIO, cgi, os 
    30 import mimetypes, sha, random, string, _cputil, cperror, Cookie 
     30import mimetypes, sha, random, string, _cputil, cperror, Cookie, urlparse 
    3131from lib.filter import basefilter 
    3232 
     
    385385        # For an IndexRedirect, we don't go through the regular 
    386386        #   mechanism: we return the redirect immediately 
    387         newUrl = canonicalizeUrl(inst.args[0]) 
     387        newUrl = urlparse.urljoin(cpg.request.base, inst.args[0]) 
    388388        wfile.write('%s 302\r\n' % (cpg.response.headerMap['protocolVersion'])) 
    389389        cpg.response.headerMap['Location'] = newUrl 
     
    535535 
    536536    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 canonical 
    542         if url[0] == '/': 
    543             # URL was absolute: we just add the request.base in front of it 
    544             url = cpg.request.base + url 
    545         else: 
    546             # URL was relative 
    547             if cpg.request.browserUrl == cpg.request.base: 
    548                 # browserUrl is request.base 
    549                 url = cpg.request.base + '/' + url 
    550             else: 
    551                 i = cpg.request.browserUrl.rfind('/') 
    552                 url = cpg.request.browserUrl[:i+1] + url 
    553     return url 
  • trunk/cherrypy/lib/httptools.py

    r124 r156  
    3232 
    3333from cherrypy import cpg 
     34import urlparse 
    3435 
    3536def canonicalizeUrl(url): 
    3637    """ 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) 
    5139 
    5240def redirect(url): 
  • trunk/cherrypy/test/test.py

    r108 r156  
    167167    print "**** THE ABOVE TESTS FAILED" 
    168168    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" 
    170170 
    171171else: 
  • trunk/cherrypy/test/testObjectMapping.py

    r122 r156  
    3131code = """ 
    3232from cherrypy import cpg 
     33from cherrypy.lib import httptools 
    3334class Root: 
    3435    def index(self, name="world"): 
     
    4445        return repr(p) 
    4546    extra.exposed = True 
     47    def redirect(self): 
     48        return httptools.redirect('dir1/') 
     49    redirect.exposed = True 
    4650    def notExposed(self): 
    4751        return "not exposed" 
     
    8892        " and cpg.response.headerMap['Location'] == 'http://127.0.0.1/dir1/dir2/'"), 
    8993    ("/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/'"), 
    9096] 
    9197 

Hosted by WebFaction

Log in as guest/cpguest to create tickets