fix: replace lua patterns for rewrite finding

This commit is contained in:
Iain Learmonth 2025-05-07 18:25:55 +01:00
parent f7b2b6d8dd
commit 0214a278da
2 changed files with 5 additions and 5 deletions

View file

@ -27,7 +27,7 @@ local function rewrite_body(body)
-- Rewrite links for assets and outbound links to other mirrored sites
local pool_map = ngx.ctx.jasima_pool_map
if pool_map then
body = body:gsub("//([a-zA-Z0-9%.%-]+%.[a-zA-Z0-9]+)/", utils.get_mirror)
body = body:gsub("//([%a%d%.-]+%.[%a%d-]+)/+", utils.get_mirror)
end
-- Add Matomo tracking code
if ngx.ctx.jasima_config.matomo_site_id then
@ -37,8 +37,8 @@ local function rewrite_body(body)
-- Handle first party Tealium installations
if ngx.ctx.jasima_host_tealium then
local escaped_host = ngx.ctx.jasima_host_tealium:gsub("%.", "%%.")
body = body:gsub("(https:)??//" .. escaped_host .. "/", "/utag/" .. ngx.ctx.jasima_config.first_party_tealium.account .. "/")
body = body:gsub("//tags.tiqcdn.com/", "/")
body = body:gsub("https://" .. escaped_host .. "/+", "/utag/" .. ngx.ctx.jasima_config.first_party_tealium.account .. "/")
body = body:gsub("//tags.tiqcdn.com/+", "/")
if ngx.var.jasima_host_connect == "tags.tiqcdn.com" and ngx.ctx.jasima_host_adobe then
body, count = body:gsub([[return"http"%+%(a%.ssl%?"s":""%)%+"://"%+b%+"/b/ss/]], [[return"/b/ss/]])
ngx.log(ngx.DEBUG, "Performing rewrite for Adobe Analytics in Tealium tag " .. count)
@ -47,7 +47,7 @@ local function rewrite_body(body)
-- Handle first party Adobe Analytics
if ngx.ctx.jasima_host_adobe then
local escaped_host = ngx.ctx.jasima_host_adobe:gsub("%.", "%%.")
body = body:gsub("(https:)??//" .. escaped_host .. "/", "/")
body = body:gsub("https://" .. escaped_host .. "/+", "/")
end
return body
end

View file

@ -23,6 +23,6 @@ end
if ngx.header["Location"] then
if ngx.ctx.jasima_pool_map then
local location = ngx.header["Location"]
ngx.header["Location"] = location:gsub("//([a-zA-Z0-9%.%-]+%.[a-zA-Z0-9]+)/", utils.get_mirror)
ngx.header["Location"] = location:gsub("//([%a%d%.-]+%.[%a%d-]+)/+", utils.get_mirror)
end
end