From 5bcd2637c93dda90b9a1fdb785c5f4b08a04f9e0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 21 Mar 2011 16:29:07 +0100 Subject: [PATCH] Include URL parameters in URL. --- .../pterodactylus/sone/web/SoneTemplatePage.java | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java index 5604c82..a6a87df 100644 --- a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java @@ -17,6 +17,8 @@ package net.pterodactylus.sone.web; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.Arrays; import java.util.Collection; @@ -28,6 +30,7 @@ import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; import freenet.clients.http.SessionManager.Session; import freenet.clients.http.ToadletContext; +import freenet.support.api.HTTPRequest; /** * Base page for the Freetalk web interface. @@ -204,7 +207,26 @@ public class SoneTemplatePage extends TemplatePage { @Override protected String getRedirectTarget(Page.Request request) { if (requiresLogin() && (getCurrentSone(request.getToadletContext(), false) == null)) { - return "login.html?target=" + request.getHttpRequest().getPath(); + HTTPRequest httpRequest = request.getHttpRequest(); + String originalUrl = httpRequest.getPath(); + if (httpRequest.hasParameters()) { + StringBuilder requestParameters = new StringBuilder(); + for (String parameterName : httpRequest.getParameterNames()) { + if (requestParameters.length() > 0) { + requestParameters.append('&'); + } + String[] parameterValues = httpRequest.getMultipleParam(parameterName); + for (String parameterValue : parameterValues) { + try { + requestParameters.append(URLEncoder.encode(parameterName, "UTF-8")).append('=').append(URLEncoder.encode(parameterValue, "UTF-8")); + } catch (UnsupportedEncodingException uee1) { + /* A JVM without UTF-8? I don’t think so. */ + } + } + } + originalUrl += "?" + requestParameters.toString(); + } + return "login.html?target=" + originalUrl; } return null; } -- 2.7.4