Comparison

plugins/mod_http.lua @ 11385:c81b6b8c6b19

mod_http: Optimize proxy IP check No need to do a subnet match comparison to see if two IP addresses match exactly.
author Kim Alvefur <zash@zash.se>
date Thu, 18 Feb 2021 10:41:04 +0100
parent 11383:98b7ae7064b2
child 11387:4f97b33e2596
comparison
equal deleted inserted replaced
11384:f9edf26c66fc 11385:c81b6b8c6b19
221 module.add_host(module); -- set up handling on global context too 221 module.add_host(module); -- set up handling on global context too
222 222
223 local trusted_proxies = module:get_option_set("trusted_proxies", { "127.0.0.1", "::1" })._items; 223 local trusted_proxies = module:get_option_set("trusted_proxies", { "127.0.0.1", "::1" })._items;
224 224
225 local function is_trusted_proxy(ip) 225 local function is_trusted_proxy(ip)
226 if trusted_proxies[ip] then
227 return true;
228 end
226 local parsed_ip = new_ip(ip) 229 local parsed_ip = new_ip(ip)
227 for trusted_proxy in trusted_proxies do 230 for trusted_proxy in trusted_proxies do
228 if match_ip(parsed_ip, parse_cidr(trusted_proxy)) then 231 if match_ip(parsed_ip, parse_cidr(trusted_proxy)) then
229 return true; 232 return true;
230 end 233 end