Comparison

mod_rest/mod_rest.lua @ 5961:2739d3db591f

mod_rest: Normalize case after filtering out non-match Prevents an attempt to index a nil value
author Kim Alvefur <zash@zash.se>
date Sun, 14 Jul 2024 18:01:24 +0200 (8 months ago)
parent 5960:d5e6617e47cc
child 5962:667ce80937fa
comparison
equal deleted inserted replaced
5960:d5e6617e47cc 5961:2739d3db591f
51 size = { code = 413; type = "modify"; condition = "resource-constraint", text = "Payload too large" }; 51 size = { code = 413; type = "modify"; condition = "resource-constraint", text = "Payload too large" };
52 }); 52 });
53 53
54 local function check_credentials(request) -- > session | boolean, error 54 local function check_credentials(request) -- > session | boolean, error
55 local auth_type, auth_data = string.match(request.headers.authorization, "^(%S+)%s(.+)$"); 55 local auth_type, auth_data = string.match(request.headers.authorization, "^(%S+)%s(.+)$");
56 auth_type = auth_type:lower();
57 if not (auth_type and auth_data) or not auth_mechanisms:contains(auth_type) then 56 if not (auth_type and auth_data) or not auth_mechanisms:contains(auth_type) then
58 return nil, post_errors.new("noauthz", { request = request }); 57 return nil, post_errors.new("noauthz", { request = request });
59 end 58 end
59 auth_type = auth_type:lower();
60 60
61 if auth_type == "basic" then 61 if auth_type == "basic" then
62 local creds = base64.decode(auth_data); 62 local creds = base64.decode(auth_data);
63 if not creds then 63 if not creds then
64 return nil, post_errors.new("malformauthz", { request = request }); 64 return nil, post_errors.new("malformauthz", { request = request });