get REST API port from settings if it's not in Host header

This commit is contained in:
jesopo 2019-09-10 16:39:44 +01:00
parent d2de2cca7d
commit a02bfdf157

View file

@ -77,11 +77,15 @@ class Handler(http.server.BaseHTTPRequestHandler):
def url_for(self, headers, route, endpoint, get_params={}):
if "Host" in headers:
host = headers["Host"]
host, _, port = headers["Host"].partition(":")
if not port:
port = _bot.config.get("api-port", "5000")
get_params_str = ""
if get_params:
get_params_str = "?%s" % urllib.parse.urlencode(get_params)
return "%s/%s/%s%s" % (host, route, endpoint, get_params_str)
return "%s:%d/%s/%s%s" % (host, port, route, endpoint,
get_params_str)
else:
return None
def _url_for(self, headers):