bw - fix missing location header in http to https redirects

This commit is contained in:
florian 2024-03-16 15:28:19 +01:00
parent 1f6a55c4e0
commit de98fe4bb9
No known key found for this signature in database
GPG key ID: 93EE47CC3D061500
5 changed files with 20 additions and 2 deletions

View file

@ -115,6 +115,7 @@ access_by_lua_block {
end
logger:log(NOTICE, plugin_id .. " redirect to " .. ret.redirect .. " : " .. ret.msg)
redirect = ret.redirect
ctx.bw.location_header = redirect
break
end
end

View file

@ -19,6 +19,14 @@ function errors:initialize(ctx)
plugin.initialize(self, "errors", ctx)
-- Default error texts
self.default_errors = {
["301"] = {
title = "Moved Permanently",
text = "The requested page has moved to a new url.",
},
["302"] = {
title = "Found",
text = "The requested page has moved temporarily to a new url.",
},
["400"] = {
title = "Bad Request",
text = "The server did not understand the request.",

View file

@ -16,7 +16,7 @@
},
"INTERCEPTED_ERROR_CODES": {
"context": "multisite",
"default": "400 401 403 404 405 413 429 500 501 502 503 504",
"default": "301 302 400 401 403 404 405 413 429 500 501 502 503 504",
"help": "List of HTTP error code intercepted by BunkerWeb",
"id": "intercepted-error-codes",
"label": "Intercepted error codes",

View file

@ -46,6 +46,15 @@ function misc:access()
return self:ret(true, "method " .. method .. " is not allowed", HTTP_NOT_ALLOWED)
end
function misc:header()
-- Add Location header if needed
if self.ctx.bw.location_header then
ngx.header["Location"] = self.ctx.bw.location_header
return self:ret(true, "edited location header")
end
return self:ret(true, "no location header needed")
end
function misc:log_default()
if self.variables["DISABLE_DEFAULT_SERVER"] == "yes" then
self:set_metric("counters", "failed_default", 1)

View file

@ -31,7 +31,7 @@
"cors",
"antibot"
],
"headers": ["headers", "cors", "reverseproxy", "clientcache", "antibot"],
"headers": ["headers", "cors", "reverseproxy", "clientcache", "antibot", "misc"],
"log": ["badbehavior", "bunkernet", "errors", "metrics"],
"preread": [
"whitelist",