Software /
code /
prosody
Comparison
plugins/mod_http.lua @ 11397:27a22a1f141c
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 30 Dec 2019 09:50:59 +0100 |
parent | 11396:f6bb3b193277 |
child | 11399:d5d895313be2 |
comparison
equal
deleted
inserted
replaced
11396:f6bb3b193277 | 11397:27a22a1f141c |
---|---|
127 end | 127 end |
128 apps[app_name] = apps[app_name] or {}; | 128 apps[app_name] = apps[app_name] or {}; |
129 local app_handlers = apps[app_name]; | 129 local app_handlers = apps[app_name]; |
130 | 130 |
131 local app_methods = opt_methods; | 131 local app_methods = opt_methods; |
132 local app_headers = opt_headers; | |
132 local app_credentials = opt_credentials; | 133 local app_credentials = opt_credentials; |
133 | 134 |
134 local function cors_handler(event_data) | 135 local function cors_handler(event_data) |
135 local request, response = event_data.request, event_data.response; | 136 local request, response = event_data.request, event_data.response; |
136 apply_cors_headers(response, app_methods, opt_headers, opt_max_age, app_credentials, request.headers.origin); | 137 apply_cors_headers(response, app_methods, app_headers, opt_max_age, app_credentials, request.headers.origin); |
137 end | 138 end |
138 | 139 |
139 local function options_handler(event_data) | 140 local function options_handler(event_data) |
140 cors_handler(event_data); | 141 cors_handler(event_data); |
141 return ""; | 142 return ""; |
143 | 144 |
144 if event.item.cors then | 145 if event.item.cors then |
145 local cors = event.item.cors; | 146 local cors = event.item.cors; |
146 if cors.credentials ~= nil then | 147 if cors.credentials ~= nil then |
147 app_credentials = cors.credentials; | 148 app_credentials = cors.credentials; |
149 end | |
150 if cors.headers then | |
151 for header, enable in pairs(cors.headers) do | |
152 if enable and not app_headers:contains(header) then | |
153 app_headers = app_headers + set.new { header }; | |
154 elseif not enable and app_headers:contains(header) then | |
155 app_headers = app_headers - set.new { header }; | |
156 end | |
157 end | |
148 end | 158 end |
149 end | 159 end |
150 | 160 |
151 local streaming = event.item.streaming_uploads; | 161 local streaming = event.item.streaming_uploads; |
152 | 162 |