fix: check for config before rewriting

This commit is contained in:
Iain Learmonth 2025-05-17 16:09:42 +01:00
parent b7cf5a5084
commit 5fe0739635
2 changed files with 42 additions and 38 deletions

View file

@ -52,7 +52,8 @@ local function rewrite_body(body)
return body
end
if ngx.ctx.rewriting then
if ngx.ctx.jasima_config then
if ngx.ctx.rewriting then
local chunk = ngx.arg[1]
local eof = ngx.arg[2]
@ -70,4 +71,5 @@ if ngx.ctx.rewriting then
else
ngx.arg[1] = nil
end
end
end

View file

@ -1,10 +1,11 @@
local utils = require "utils"
if ngx.ctx.jasima_config.rewrite_disable then
if ngx.ctx.jasima_config then
if ngx.ctx.jasima_config.rewrite_disable then
return
end
end
if ngx.header["Content-Type"] then
if ngx.header["Content-Type"] then
local content_type = ngx.header["Content-Type"]:lower()
if content_type:find("text/html") or
content_type:find("text/css") or
@ -19,11 +20,12 @@ if ngx.header["Content-Type"] then
ngx.ctx.rewriting = true
ngx.header["Content-Length"] = nil -- We're rewriting the body so this has the wrong value if set
end
end
end
if ngx.header["Location"] then
if ngx.header["Location"] then
if ngx.ctx.jasima_pool_map then
local location = ngx.header["Location"]
ngx.header["Location"] = location:gsub("//([%a%d%.-]+%.[%a%d-]+)/+", utils.get_mirror)
end
end
end