mod_http: Allow disabling CORS in the http_cors_override option and by default
Fixes #1779.
Due to an oversight in the logic, if the user set 'enabled' to false in an
override, it would disable the item's requested CORS settings, but still apply
Prosody's default CORS policy.
This change ensures that 'enabled = false' will now disable CORS entirely for
the requested item.
Due to the new structure of the code, it was necessary to have a flag to say
whether CORS is to be applied at all. Rather than hard-coding 'true' here, I
chose to add a new option: 'http_default_cors_enabled'. This is a boolean that
allows the operator to disable Prosody's default CORS policy entirely (the one
that is used when a module or config does not override it). This makes it
easier to disable CORS and then selectively enable it only on services you
want it on.
local lfs = require"lfs";
local hg = { };
function hg.check_id(path)
if lfs.attributes(path, 'mode') ~= "directory" then
return nil, "not a directory";
end
local hg_dirstate = io.open(path.."/.hg/dirstate");
local hgid, hgrepo
if hg_dirstate then
hgid = ("%02x%02x%02x%02x%02x%02x"):format(hg_dirstate:read(6):byte(1, 6));
hg_dirstate:close();
local hg_changelog = io.open(path.."/.hg/store/00changelog.i");
if hg_changelog then
hg_changelog:seek("set", 0x20);
hgrepo = ("%02x%02x%02x%02x%02x%02x"):format(hg_changelog:read(6):byte(1, 6));
hg_changelog:close();
end
else
local hg_archival,e = io.open(path.."/.hg_archival.txt"); -- luacheck: ignore 211/e
if hg_archival then
local repo = hg_archival:read("*l");
local node = hg_archival:read("*l");
hg_archival:close()
hgid = node and node:match("^node: (%x%x%x%x%x%x%x%x%x%x%x%x)")
hgrepo = repo and repo:match("^repo: (%x%x%x%x%x%x%x%x%x%x%x%x)")
end
end
return hgid, hgrepo;
end
return hg;