From 09b178dca8a852c475df1189d028d995c4936405 Mon Sep 17 00:00:00 2001 From: irl Date: Mon, 28 Apr 2025 15:35:00 +0100 Subject: [PATCH] feat: improve logging in access.lua --- src/lua/access.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lua/access.lua b/src/lua/access.lua index 8f97d62..6a0dcc0 100644 --- a/src/lua/access.lua +++ b/src/lua/access.lua @@ -7,6 +7,7 @@ local utils = require "utils" local jasima_host = config.get_jasima_host() ngx.ctx.jasima_host = jasima_host if not jasima_host then + ngx.log(ngx.DEBUG, "no host specified via header or cookie") return ngx.exit(400) end @@ -14,21 +15,25 @@ local err ngx.ctx.jasima_config, err = config.load_config(jasima_host) if err then ngx.status = 500 - ngx.log(ngx.ERR, "Could not load config: " .. err) + ngx.log(ngx.ERR, "could not load config: " .. err) return ngx.exit(500) end if not ngx.ctx.jasima_config then ngx.status = 403 - ngx.log(ngx.ERR, "Requested a canonical host that has no configuration specified: " .. jasima_host) + ngx.log(ngx.INFO, "requested a canonical host that has no configuration specified: " .. jasima_host) ngx.exit(403) end local country = geo.viewer_country() -if not ngx.ctx.jasima_config.geo_redirect_disable and not geo.needs_mirror(country) then - local request_uri = ngx.var.request_uri - local new_url = "https://" .. jasima_host .. request_uri - return ngx.redirect(new_url, ngx.HTTP_MOVED_TEMPORARILY) +if not ngx.ctx.jasima_config.geo_redirect_disable then + ngx.log(ngx.DEBUG, "geo_redirect_disable not configured for site " .. jasima_host) + if not geo.needs_mirror(country) then + ngx.log(ngx.DEBUG, "mirror is not needed for viewer in " .. country .. " for " .. jasima_host .. ", redirecting") + local request_uri = ngx.var.request_uri + local new_url = "https://" .. jasima_host .. request_uri + return ngx.redirect(new_url, ngx.HTTP_MOVED_TEMPORARILY) + end end -- Get jasima_pool (not critical) @@ -36,7 +41,7 @@ local jasima_pool = config.get_jasima_pool() ngx.ctx.jasima_pool_map, err = config.load_pool_mapping(jasima_pool) if err then ngx.status = 500 - ngx.log(ngx.WARN, "Could not load pool mapping: " .. err) + ngx.log(ngx.WARN, "could not load requested pool mapping: " .. err) return ngx.exit(500) end