fix block page

This commit is contained in:
wiaamm
2025-12-03 10:30:24 +02:00
parent 8b036e639a
commit ac61cc875f
2 changed files with 25 additions and 30 deletions

View File

@@ -90,7 +90,8 @@ function nano.handle_custom_response(session_data, response)
if not attachment then
kong.log.warn("Cannot handle custom response: Attachment not available for worker ", worker_id, " - failing open")
return kong.response.exit(200, "Request allowed due to attachment unavailability")
kong.response.exit(200, "Request allowed due to attachment unavailability")
return
end
local response_type = nano_attachment.get_web_response_type(attachment, session_data, response)
@@ -103,19 +104,22 @@ function nano.handle_custom_response(session_data, response)
code = 403
end
kong.log.err("Response code only: ", code)
return kong.response.exit(code, "")
kong.response.exit(code, "")
return
end
if response_type == nano.WebResponseType.REDIRECT_WEB_RESPONSE then
local location = nano_attachment.get_redirect_page(attachment, session_data, response)
kong.log.err("Redirect response to: ", location)
return kong.response.exit(307, "", { ["Location"] = location })
kong.response.exit(307, "", { ["Location"] = location })
return
end
local block_page = nano_attachment.get_block_page(attachment, session_data, response)
if not block_page then
kong.log.err("Failed to retrieve custom block page for session ", session_data)
return kong.response.exit(500, { message = "Internal Server Error" })
kong.response.exit(500, { message = "Internal Server Error" })
return
end
local code = nano_attachment.get_response_code(response)
if not code or code < 100 or code > 599 then
@@ -123,8 +127,7 @@ function nano.handle_custom_response(session_data, response)
code = 403
end
kong.log.err("Block page response with code: ", code, ", page length: ", #block_page)
return kong.response.exit(code, block_page, { ["Content-Type"] = "text/html" })
kong.response.exit(code, block_page, { ["Content-Type"] = "text/html" })
end