Mercurial > prosody-hg
comparison plugins/mod_http.lua @ 12191:8b57362f1176
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.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 27 Nov 2021 12:26:15 +0100 |
| parents | 94253e02d47d |
| children | 6a772a0c0dfd |
comparison
equal
deleted
inserted
replaced
| 12190:3616128cd2e3 | 12191:8b57362f1176 |
|---|---|
| 72 local ports_by_scheme = { http = 80, https = 443, }; | 72 local ports_by_scheme = { http = 80, https = 443, }; |
| 73 | 73 |
| 74 -- Helper to deduce a module's external URL | 74 -- Helper to deduce a module's external URL |
| 75 function moduleapi.http_url(module, app_name, default_path) | 75 function moduleapi.http_url(module, app_name, default_path) |
| 76 app_name = app_name or (module.name:gsub("^http_", "")); | 76 app_name = app_name or (module.name:gsub("^http_", "")); |
| 77 local external_url = url_parse(module:get_option_string("http_external_url")) or {}; | 77 |
| 78 if external_url.scheme and external_url.port == nil then | 78 local external_url = url_parse(module:get_option_string("http_external_url")); |
| 79 external_url.port = ports_by_scheme[external_url.scheme]; | 79 if external_url then |
| 80 end | 80 local url = { |
| 81 scheme = external_url.scheme; | |
| 82 host = external_url.host; | |
| 83 port = tonumber(external_url.port) or ports_by_scheme[external_url.scheme]; | |
| 84 path = normalize_path(external_url.path or "/", true) | |
| 85 .. (get_base_path(module, app_name, default_path or "/" .. app_name):sub(2)); | |
| 86 } | |
| 87 if ports_by_scheme[url.scheme] == url.port then url.port = nil end | |
| 88 return url_build(url); | |
| 89 end | |
| 90 | |
| 81 local services = portmanager.get_active_services(); | 91 local services = portmanager.get_active_services(); |
| 82 local http_services = services:get("https") or services:get("http") or {}; | 92 local http_services = services:get("https") or services:get("http") or {}; |
| 83 for interface, ports in pairs(http_services) do -- luacheck: ignore 213/interface | 93 for interface, ports in pairs(http_services) do -- luacheck: ignore 213/interface |
| 84 for port, service in pairs(ports) do -- luacheck: ignore 512 | 94 for port, service in pairs(ports) do -- luacheck: ignore 512 |
| 85 local url = { | 95 local url = { |
| 86 scheme = (external_url.scheme or service[1].service.name); | 96 scheme = service[1].service.name; |
| 87 host = (external_url.host or module:get_option_string("http_host", module.host)); | 97 host = module:get_option_string("http_host", module.host); |
| 88 port = tonumber(external_url.port) or port or 80; | 98 port = port; |
| 89 path = normalize_path(external_url.path or "/", true).. | 99 path = get_base_path(module, app_name, default_path or "/" .. app_name); |
| 90 (get_base_path(module, app_name, default_path or "/"..app_name):sub(2)); | |
| 91 } | 100 } |
| 92 if ports_by_scheme[url.scheme] == url.port then url.port = nil end | 101 if ports_by_scheme[url.scheme] == url.port then url.port = nil end |
| 93 return url_build(url); | 102 return url_build(url); |
| 94 end | 103 end |
| 95 end | 104 end |
