comparison mod_rest/mod_rest.lua @ 3815:1a0a612d36bc

mod_rest: Short-circuit type selection if accept header
author Kim Alvefur <zash@zash.se>
date Wed, 01 Jan 2020 16:37:18 +0100
parents 0dede5b0ab27
children 8473fd2d09c1
comparison
equal deleted inserted replaced
3814:0dede5b0ab27 3815:1a0a612d36bc
43 local supported_types = { "application/xmpp+xml", "application/json" }; 43 local supported_types = { "application/xmpp+xml", "application/json" };
44 44
45 local function decide_type(accept) 45 local function decide_type(accept)
46 -- assumes the accept header is sorted 46 -- assumes the accept header is sorted
47 local ret = supported_types[1]; 47 local ret = supported_types[1];
48 if not accept then
49 return ret;
50 end
51 for i = 2, #supported_types do 48 for i = 2, #supported_types do
52 if (accept:find(supported_types[i], 1, true) or 1000) < (accept:find(ret, 1, true) or 1000) then 49 if (accept:find(supported_types[i], 1, true) or 1000) < (accept:find(ret, 1, true) or 1000) then
53 ret = supported_types[i]; 50 ret = supported_types[i];
54 end 51 end
55 end 52 end