~ubuntu-branches/ubuntu/precise/trac/precise

« back to all changes in this revision

Viewing changes to trac/web/api.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2006-07-03 22:03:47 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060703220347-4vhz82319vn0jws6
Tags: 0.9.5-2ubuntu1
* Merge from debian unstable:
  - debian/{control,dirs}: Continue to use python2.4.
  - debian/rules: Use Debian Sid's version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
247
247
    If the `path` parameter is specified, the path is appended to the URL.
248
248
    Otherwise, only a URL with the components scheme, host and port is returned.
249
249
    """
250
 
    host = req.get_header('Host')
251
 
    if req.get_header('X-Forwarded-Host'):
252
 
        host = req.get_header('X-Forwarded-Host')
253
 
    if not host:
254
 
        # Missing host header, so reconstruct the host from the
255
 
        # server name and port
256
 
        default_port = {'http': 80, 'https': 443}
257
 
        if req.server_port and req.server_port != default_port[req.scheme]:
258
 
            host = '%s:%d' % (req.server_name, req.server_port)
259
 
        else:
260
 
            host = req.server_name
261
 
    if not path:
262
 
        path = req.cgi_location
263
 
    return urlparse.urlunparse((req.scheme, host, path, None, None, None))
 
250
    if hasattr(req, 'base_url'):
 
251
        scheme, host, _, _, _, _ = urlparse.urlparse(req.base_url)
 
252
    else:
 
253
        scheme = req.scheme
 
254
        host = req.get_header('Host')
 
255
        if not host:
 
256
            # Missing host header, so reconstruct the host from the
 
257
            # server name and port
 
258
            default_port = {'http': 80, 'https': 443}
 
259
            if req.server_port and req.server_port != default_port[scheme]:
 
260
                host = '%s:%d' % (req.server_name, req.server_port)
 
261
            else:
 
262
                host = req.server_name
 
263
        if not path:
 
264
            path = req.cgi_location
 
265
    return urlparse.urlunparse((scheme, host, path, None, None, None))