|
@@ -5,6 +5,7 @@ local timer = require "util.timer";
|
5
|
5
|
local http = require "net.http";
|
6
|
6
|
local cache = require "util.cache";
|
7
|
7
|
local array = require "util.array";
|
|
8
|
+local is_set = require 'util.set'.is_set;
|
8
|
9
|
|
9
|
10
|
local http_timeout = 30;
|
10
|
11
|
local have_async, async = pcall(require, "util.async");
|
|
@@ -288,14 +289,25 @@ function starts_with(str, start)
|
288
|
289
|
end
|
289
|
290
|
|
290
|
291
|
function starts_with_one_of(str, prefixes)
|
291
|
|
- if not str then
|
|
292
|
+ if not str or not prefixes then
|
292
|
293
|
return false;
|
293
|
294
|
end
|
294
|
|
- for i=1,#prefixes do
|
295
|
|
- if starts_with(str, prefixes[i]) then
|
296
|
|
- return prefixes[i];
|
|
295
|
+
|
|
296
|
+ if is_set(prefixes) then
|
|
297
|
+ -- set is a table with keys and value of true
|
|
298
|
+ for k, _ in prefixes:items() do
|
|
299
|
+ if starts_with(str, k) then
|
|
300
|
+ return k;
|
|
301
|
+ end
|
|
302
|
+ end
|
|
303
|
+ else
|
|
304
|
+ for _, v in pairs(prefixes) do
|
|
305
|
+ if starts_with(str, v) then
|
|
306
|
+ return v;
|
|
307
|
+ end
|
297
|
308
|
end
|
298
|
309
|
end
|
|
310
|
+
|
299
|
311
|
return false
|
300
|
312
|
end
|
301
|
313
|
|