Comparison

plugins/mod_http.lua @ 11396:f6bb3b193277

mod_http: Allow setting the CORS credentials flag via :provides API E.g. module:provides("http", { cors = { credentials = true; }; route = { ... }; });
author Kim Alvefur <zash@zash.se>
date Mon, 30 Dec 2019 09:49:28 +0100
parent 11387:4f97b33e2596
child 11397:27a22a1f141c
comparison
equal deleted inserted replaced
11395:d336b28b4002 11396:f6bb3b193277
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_credentials = opt_credentials;
132 133
133 local function cors_handler(event_data) 134 local function cors_handler(event_data)
134 local request, response = event_data.request, event_data.response; 135 local request, response = event_data.request, event_data.response;
135 apply_cors_headers(response, app_methods, opt_headers, opt_max_age, opt_credentials, request.headers.origin); 136 apply_cors_headers(response, app_methods, opt_headers, opt_max_age, app_credentials, request.headers.origin);
136 end 137 end
137 138
138 local function options_handler(event_data) 139 local function options_handler(event_data)
139 cors_handler(event_data); 140 cors_handler(event_data);
140 return ""; 141 return "";
142 end
143
144 if event.item.cors then
145 local cors = event.item.cors;
146 if cors.credentials ~= nil then
147 app_credentials = cors.credentials;
148 end
141 end 149 end
142 150
143 local streaming = event.item.streaming_uploads; 151 local streaming = event.item.streaming_uploads;
144 152
145 for key, handler in pairs(event.item.route or {}) do 153 for key, handler in pairs(event.item.route or {}) do