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.
250
host = req.get_header('Host')
251
if req.get_header('X-Forwarded-Host'):
252
host = req.get_header('X-Forwarded-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)
260
host = req.server_name
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)
254
host = req.get_header('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)
262
host = req.server_name
264
path = req.cgi_location
265
return urlparse.urlunparse((scheme, host, path, None, None, None))