good, bad, or indifferent, because of varied testing and deployment setups,
and using multiple ports, i have the function below in my app. note that i
have database configuration for HTTPS scheme and port. It's my hack not not
run internal test and development servers on port 443. :)
def full_url(scheme="http",
a=None,
c=None,
f=None,
r=None,
args=[],
vars={},
anchor='',
path = None
):
"""
Create a fully qualified URL. The URL will use the same host as the
request was made from, but will use the specified scheme. Calls
C{gluon.html.URL()} to construct the relative path to the host.
if <scheme>_port is set in the settings table, append the port to the
domain of the created URL
@param scheme: scheme to use for the fully-qualified URL.
(default to 'http')
@param a: application (default to current if r is given)
@param c: controller (default to current if r is given)
@param f: function (default to current if r is given)
@param r: request
@param args: any arguments (optional)
@param vars: any variables (optional)
@param anchor: anchorname, without # (optional)
@param path: the relative path to use. if used overrides a,c,f,args,
and
vars (optional)
"""
port = ''
if sitesettings.has_key(scheme+"_port") and
sitesettings[scheme+"_port"]:
port = ":" + sitesettings[scheme+"_port"]
if scheme == 'https' and sitesettings.has_key("https_scheme"):
scheme = sitesettings.https_scheme
url = scheme +'://' + \
r.env.http_host.split(':')[0] + port
if path:
url = url + path
else:
url = url+URL(a=a, c=c, f=f, r=r, args=args, vars=vars,
anchor=anchor)
return url