Diff

mod_rest/mod_rest.lua @ 4734:e58ec4b3cf90

mod_rest: Add an anonymous mode Could be useful for a demo instance.
author Kim Alvefur <zash@zash.se>
date Mon, 01 Nov 2021 15:08:21 +0100
parent 4727:e6f46d1b3337
child 4735:58a20d5ac6e9
line wrap: on
line diff
--- 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