diff options
| author | 2019-09-10 16:39:44 +0100 | |
|---|---|---|
| committer | 2019-09-10 16:39:44 +0100 | |
| commit | a02bfdf157d8e1183168900f5cccfc706edd442b (patch) | |
| tree | 5265868db262dec41ea7e46193e001bd029fd9f4 | |
| parent | 'index' -> 'inbox' (diff) | |
| signature | ||
get REST API port from settings if it's not in Host header
| -rw-r--r-- | modules/rest_api.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/modules/rest_api.py b/modules/rest_api.py index 18ddf3c1..23059c21 100644 --- a/modules/rest_api.py +++ b/modules/rest_api.py @@ -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): |
