Add request/history specific regex

Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
Hadi
2026-05-18 23:44:50 +02:00
parent 0fafa52c65
commit 4f45a7c061
+44 -18
View File
@@ -4,8 +4,12 @@ Plugin = {
Auto-forward requests and exclude them from history based on patterns. Auto-forward requests and exclude them from history based on patterns.
**Config**: **Config**:
- `pattern` - whitelist: only intercept matching requests - `pattern` - whitelist: only intercept matching requests/responses and history entries
- `!pattern` - blacklist: don't intercept matching requests and exclude from history - `!pattern` - blacklist: skip matching requests/responses and history entries
- `r:pattern` - whitelist for requests/responses only (history unaffected)
- `r:!pattern` - blacklist for requests/responses only
- `h:pattern` - whitelist for history entries only (requests unaffected)
- `h:!pattern` - blacklist for history entries only
- lines starting with `#` are comments - lines starting with `#` are comments
Example (ignore static assets): Example (ignore static assets):
@@ -26,6 +30,11 @@ mytarget%.com/
!%.css$ !%.css$
!%.js$ !%.js$
!%.png$ !%.png$
```
Example (disable history — h: whitelist never matches any real URL):
```
h:^$
``` ```
]], ]],
priority = 100, priority = 100,
@@ -34,31 +43,48 @@ mytarget%.com/
on_history_entry = { sync = true }, on_history_entry = { sync = true },
} }
local whitelist = {} local blacklist = {}
local blacklist = {} local whitelist = {}
local blacklist_req = {}
local whitelist_req = {}
local blacklist_hist = {}
local whitelist_hist = {}
function on_config(config_text) function on_config(config_text)
whitelist = {} blacklist, whitelist = {}, {}
blacklist = {} blacklist_req, whitelist_req = {}, {}
blacklist_hist, whitelist_hist = {}, {}
for line in config_text:gmatch("[^\n]+") do for line in config_text:gmatch("[^\n]+") do
local trimmed = line:match("^%s*(.-)%s*$") local trimmed = line:match("^%s*(.-)%s*$")
if trimmed ~= "" and trimmed:sub(1, 1) ~= "#" then if trimmed ~= "" and trimmed:sub(1, 1) ~= "#" then
if trimmed:sub(1, 1) == "!" then local scope = trimmed:match("^([rh]):")
table.insert(blacklist, trimmed:sub(2)) local rest = scope and trimmed:sub(3) or trimmed
local is_bl = rest:sub(1, 1) == "!"
local pattern = is_bl and rest:sub(2) or rest
if scope == "r" then
table.insert(is_bl and blacklist_req or whitelist_req, pattern)
elseif scope == "h" then
table.insert(is_bl and blacklist_hist or whitelist_hist, pattern)
else else
table.insert(whitelist, trimmed) table.insert(is_bl and blacklist or whitelist, pattern)
end end
end end
end end
end end
local function should_skip(url) local function check_skip(url, bl_extra, wl_extra)
for _, pattern in ipairs(blacklist) do for _, p in ipairs(blacklist) do
if url:match(pattern) then return true end if url:match(p) then return true end
end end
if #whitelist > 0 then for _, p in ipairs(bl_extra) do
for _, pattern in ipairs(whitelist) do if url:match(p) then return true end
if url:match(pattern) then return false end end
local wl = {}
for _, p in ipairs(whitelist) do wl[#wl + 1] = p end
for _, p in ipairs(wl_extra) do wl[#wl + 1] = p end
if #wl > 0 then
for _, p in ipairs(wl) do
if url:match(p) then return false end
end end
return true return true
end end
@@ -66,13 +92,13 @@ local function should_skip(url)
end end
function on_request(req) function on_request(req)
if should_skip(req.url) then return "forward" end if check_skip(req.url, blacklist_req, whitelist_req) then return "forward" end
end end
function on_response(req) function on_response(req)
if should_skip(req.url) then return "forward" end if check_skip(req.url, blacklist_req, whitelist_req) then return "forward" end
end end
function on_history_entry(entry) function on_history_entry(entry)
if should_skip(entry.host .. entry.path) then return "skip" end if check_skip(entry.host .. entry.path, blacklist_hist, whitelist_hist) then return "skip" end
end end