aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-12-30 09:50:59 +0100
committerKim Alvefur <zash@zash.se>2019-12-30 09:50:59 +0100
commitd65d38846d0f5bfc7092b0546c241fc4ee0ae85d (patch)
tree54185a97d0c7d08f7ec0616cc32377588ae50260 /plugins
parent5d4446cd13b3dd9900ebc169b2e7f2d032a8e6c9 (diff)
downloadprosody-d65d38846d0f5bfc7092b0546c241fc4ee0ae85d.tar.gz
prosody-d65d38846d0f5bfc7092b0546c241fc4ee0ae85d.zip
mod_http: Allow modifying CORS header list via :provides API
E.g. module:provides("http", { cors = { headers = { Accept = true; Expect = false; }; }; route = { ... }; }); Case might be weird.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_http.lua12
1 files changed, 11 insertions, 1 deletions
diff --git a/plugins/mod_http.lua b/plugins/mod_http.lua
index 3a33e408..a13b689b 100644
--- a/plugins/mod_http.lua
+++ b/plugins/mod_http.lua
@@ -129,11 +129,12 @@ function module.add_host(module)
local app_handlers = apps[app_name];
local app_methods = opt_methods;
+ local app_headers = opt_headers;
local app_credentials = opt_credentials;
local function cors_handler(event_data)
local request, response = event_data.request, event_data.response;
- apply_cors_headers(response, app_methods, opt_headers, opt_max_age, app_credentials, request.headers.origin);
+ apply_cors_headers(response, app_methods, app_headers, opt_max_age, app_credentials, request.headers.origin);
end
local function options_handler(event_data)
@@ -146,6 +147,15 @@ function module.add_host(module)
if cors.credentials ~= nil then
app_credentials = cors.credentials;
end
+ if cors.headers then
+ for header, enable in pairs(cors.headers) do
+ if enable and not app_headers:contains(header) then
+ app_headers = app_headers + set.new { header };
+ elseif not enable and app_headers:contains(header) then
+ app_headers = app_headers - set.new { header };
+ end
+ end
+ end
end
local streaming = event.item.streaming_uploads;