diff mod_http_pep_avatar/mod_http_pep_avatar.lua @ 3433:213679266dcb

mod_http_pep_avatar: Redirect to prepped username
author Kim Alvefur <zash@zash.se>
date Sun, 06 Jan 2019 10:26:32 +0100
parents 461429e0db58
children 00bdecb12779
line wrap: on
line diff
--- a/mod_http_pep_avatar/mod_http_pep_avatar.lua	Sun Jan 06 10:24:32 2019 +0100
+++ b/mod_http_pep_avatar/mod_http_pep_avatar.lua	Sun Jan 06 10:26:32 2019 +0100
@@ -6,6 +6,7 @@
 local um = require "core.usermanager";
 local nodeprep = require "util.encodings".stringprep.nodeprep;
 local base64_decode = require "util.encodings".base64.decode;
+local urlencode = require "util.http".urlencode;
 
 module:depends("http")
 module:provides("http", {
@@ -14,8 +15,12 @@
 			local request, response = event.request, event.response;
 			local actor = request.ip;
 
-			user = nodeprep(user);
-			if not user then return 400; end
+			local prepped = nodeprep(user);
+			if not prepped then return 400; end
+			if prepped ~= user then
+				response.headers.location = module:http_url() .. "/" .. urlencode(prepped);
+				return 302;
+			end
 			if not um.user_exists(user, module.host) then
 				return 404;
 			end