aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_http.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-11-27 12:26:15 +0100
committerKim Alvefur <zash@zash.se>2021-11-27 12:26:15 +0100
commit77630b72ff324419b9d0b062c25e62f54661d3d1 (patch)
tree9472c95a47253bb76b8e8f715e0ac3f2370c5036 /plugins/mod_http.lua
parentcced954ac3e55bff2dabb86c555044eb007e44d4 (diff)
downloadprosody-77630b72ff324419b9d0b062c25e62f54661d3d1.tar.gz
prosody-77630b72ff324419b9d0b062c25e62f54661d3d1.zip
mod_http: Skip querying portmanager when http_external_url when is set
When http_external_url is set then the portmanager usage only really serves as a check of whether any http service is enabled at all. Should allow generating an URL from prosodyctl when http_external_url is set.
Diffstat (limited to 'plugins/mod_http.lua')
-rw-r--r--plugins/mod_http.lua25
1 files changed, 17 insertions, 8 deletions
diff --git a/plugins/mod_http.lua b/plugins/mod_http.lua
index c7795089..43b328bd 100644
--- a/plugins/mod_http.lua
+++ b/plugins/mod_http.lua
@@ -74,20 +74,29 @@ local ports_by_scheme = { http = 80, https = 443, };
-- Helper to deduce a module's external URL
function moduleapi.http_url(module, app_name, default_path)
app_name = app_name or (module.name:gsub("^http_", ""));
- local external_url = url_parse(module:get_option_string("http_external_url")) or {};
- if external_url.scheme and external_url.port == nil then
- external_url.port = ports_by_scheme[external_url.scheme];
+
+ local external_url = url_parse(module:get_option_string("http_external_url"));
+ if external_url then
+ local url = {
+ scheme = external_url.scheme;
+ host = external_url.host;
+ port = tonumber(external_url.port) or ports_by_scheme[external_url.scheme];
+ path = normalize_path(external_url.path or "/", true)
+ .. (get_base_path(module, app_name, default_path or "/" .. app_name):sub(2));
+ }
+ if ports_by_scheme[url.scheme] == url.port then url.port = nil end
+ return url_build(url);
end
+
local services = portmanager.get_active_services();
local http_services = services:get("https") or services:get("http") or {};
for interface, ports in pairs(http_services) do -- luacheck: ignore 213/interface
for port, service in pairs(ports) do -- luacheck: ignore 512
local url = {
- scheme = (external_url.scheme or service[1].service.name);
- host = (external_url.host or module:get_option_string("http_host", module.host));
- port = tonumber(external_url.port) or port or 80;
- path = normalize_path(external_url.path or "/", true)..
- (get_base_path(module, app_name, default_path or "/"..app_name):sub(2));
+ scheme = service[1].service.name;
+ host = module:get_option_string("http_host", module.host);
+ port = port;
+ path = get_base_path(module, app_name, default_path or "/" .. app_name);
}
if ports_by_scheme[url.scheme] == url.port then url.port = nil end
return url_build(url);