Software /
code /
prosody
Comparison
plugins/mod_http.lua @ 9376:220468f7a103
mod_http: Support global HTTP modules
Such modules simply ignore the Host header and always handle the same path.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 21 Sep 2018 23:49:56 +0200 |
parent | 9338:9beb767295d4 |
child | 9503:3456496d5218 |
comparison
equal
deleted
inserted
replaced
9375:816591db764d | 9376:220468f7a103 |
---|---|
36 return nil; | 36 return nil; |
37 end | 37 end |
38 if app_path == "/" and path:sub(1,1) == "/" then | 38 if app_path == "/" and path:sub(1,1) == "/" then |
39 app_path = ""; | 39 app_path = ""; |
40 end | 40 end |
41 return method:upper().." "..host..app_path..path; | 41 if host == "*" then |
42 return method:upper().." "..app_path..path; | |
43 else | |
44 return method:upper().." "..host..app_path..path; | |
45 end | |
42 end | 46 end |
43 | 47 |
44 local function get_base_path(host_module, app_name, default_app_path) | 48 local function get_base_path(host_module, app_name, default_app_path) |
45 return (normalize_path(host_module:get_option("http_paths", {})[app_name] -- Host | 49 return (normalize_path(host_module:get_option("http_paths", {})[app_name] -- Host |
46 or module:get_option("http_paths", {})[app_name] -- Global | 50 or module:get_option("http_paths", {})[app_name] -- Global |
83 module:log("warn", "No http ports enabled, can't generate an external URL"); | 87 module:log("warn", "No http ports enabled, can't generate an external URL"); |
84 return "http://disabled.invalid/"; | 88 return "http://disabled.invalid/"; |
85 end | 89 end |
86 | 90 |
87 function module.add_host(module) | 91 function module.add_host(module) |
88 local host = module:get_option_string("http_host", module.host); | 92 local host = module.host; |
93 if host ~= "*" then | |
94 host = module:get_option_string("http_host", host); | |
95 end | |
89 local apps = {}; | 96 local apps = {}; |
90 module.environment.apps = apps; | 97 module.environment.apps = apps; |
91 local function http_app_added(event) | 98 local function http_app_added(event) |
92 local app_name = event.item.name; | 99 local app_name = event.item.name; |
93 local default_app_path = event.item.default_path or "/"..app_name; | 100 local default_app_path = event.item.default_path or "/"..app_name; |
142 end | 149 end |
143 end | 150 end |
144 | 151 |
145 module:handle_items("http-provider", http_app_added, http_app_removed); | 152 module:handle_items("http-provider", http_app_added, http_app_removed); |
146 | 153 |
147 server.add_host(host); | 154 if host ~= "*" then |
148 function module.unload() | 155 server.add_host(host); |
149 server.remove_host(host); | 156 function module.unload() |
150 end | 157 server.remove_host(host); |
151 end | 158 end |
159 end | |
160 end | |
161 | |
162 module.add_host(module); -- set up handling on global context too | |
152 | 163 |
153 local trusted_proxies = module:get_option_set("trusted_proxies", { "127.0.0.1", "::1" })._items; | 164 local trusted_proxies = module:get_option_set("trusted_proxies", { "127.0.0.1", "::1" })._items; |
154 | 165 |
155 local function get_ip_from_request(request) | 166 local function get_ip_from_request(request) |
156 local ip = request.conn:ip(); | 167 local ip = request.conn:ip(); |