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 -- Rewrite links for assets and outbound links to other mirrored sites
local pool_map = ngx.ctx.jasima_pool_map local pool_map = ngx.ctx.jasima_pool_map
if pool_map then 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 end
-- Add Matomo tracking code -- Add Matomo tracking code
if ngx.ctx.jasima_config.matomo_site_id then if ngx.ctx.jasima_config.matomo_site_id then
@ -37,8 +37,8 @@ local function rewrite_body(body)
-- Handle first party Tealium installations -- Handle first party Tealium installations
if ngx.ctx.jasima_host_tealium then if ngx.ctx.jasima_host_tealium then
local escaped_host = ngx.ctx.jasima_host_tealium:gsub("%.", "%%.") 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("https://" .. escaped_host .. "/+", "/utag/" .. ngx.ctx.jasima_config.first_party_tealium.account .. "/")
body = body:gsub("//tags.tiqcdn.com/", "/") body = body:gsub("//tags.tiqcdn.com/+", "/")
if ngx.var.jasima_host_connect == "tags.tiqcdn.com" and ngx.ctx.jasima_host_adobe then 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/]]) 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) 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 -- Handle first party Adobe Analytics
if ngx.ctx.jasima_host_adobe then if ngx.ctx.jasima_host_adobe then
local escaped_host = ngx.ctx.jasima_host_adobe:gsub("%.", "%%.") local escaped_host = ngx.ctx.jasima_host_adobe:gsub("%.", "%%.")
body = body:gsub("(https:)??//" .. escaped_host .. "/", "/") body = body:gsub("https://" .. escaped_host .. "/+", "/")
end end
return body return body
end end

View file

@ -23,6 +23,6 @@ end
if ngx.header["Location"] then if ngx.header["Location"] then
if ngx.ctx.jasima_pool_map then if ngx.ctx.jasima_pool_map then
local location = ngx.header["Location"] 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
end end