# HG changeset patch # User Kim Alvefur # Date 1635775701 -3600 # Node ID e58ec4b3cf90f6e22eb755234f38ddeba07a5746 # Parent 755dd83e9214c1cfbb91bbff30fc6cc86215b174 mod_rest: Add an anonymous mode Could be useful for a demo instance. diff -r 755dd83e9214 -r e58ec4b3cf90 mod_rest/mod_rest.lua --- a/mod_rest/mod_rest.lua Wed Oct 27 20:54:54 2021 +0200 +++ b/mod_rest/mod_rest.lua Mon Nov 01 15:08:21 2021 +0100 @@ -58,6 +58,16 @@ return nil; end +if module:get_option_string("authentication") == "anonymous" and module:get_option_boolean("anonymous_rest") then + www_authenticate_header = nil; + function check_credentials(request) -- luacheck: ignore 212/request + return { + username = id.medium():lower(); + host = module.host; + } + end +end + -- (table, string) -> table local function amend_from_path(data, path) local st_kind, st_type, st_to = path:match("^([mpi]%w+)/(%w+)/(.*)$"); @@ -233,7 +243,7 @@ local echo = path == "echo"; if echo then path = nil; end - if not request.headers.authorization then + if not request.headers.authorization and www_authenticate_header then response.headers.www_authenticate = www_authenticate_header; return post_errors.new("noauthz"); else