From 75782562f9f10b67ead74bb9daa4a1411f07c5a1 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Fri, 1 Mar 2019 09:41:41 +0200 Subject: [PATCH] Fixed authentication message showing '/' --- .../plan/system/webserver/RequestHandler.java | 2 +- .../plan/system/webserver/response/Response.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/RequestHandler.java b/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/RequestHandler.java index 74ac1a759..bca3ef3b7 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/RequestHandler.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/RequestHandler.java @@ -86,7 +86,7 @@ public class RequestHandler implements HttpHandler { try { Response response = responseHandler.getResponse(request); if (response instanceof PromptAuthorizationResponse) { - responseHeaders.set("WWW-Authenticate", "Basic realm=\"/\""); + responseHeaders.set("WWW-Authenticate", response.getHeader("WWW-Authenticate").orElse("Basic realm=\"Plan WebUser (/plan register)\";")); } response.setResponseHeaders(responseHeaders); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/response/Response.java b/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/response/Response.java index ede1b373b..177a94dc6 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/response/Response.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/response/Response.java @@ -25,6 +25,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Objects; +import java.util.Optional; import java.util.zip.GZIPOutputStream; /** @@ -53,6 +54,15 @@ public abstract class Response { return header; } + public Optional getHeader(String called) { + for (String header : header.split("\r\n")) { + if (header.startsWith(called)) { + return Optional.of(header.split(": ")[1]); + } + } + return Optional.empty(); + } + public void setHeader(String header) { this.header = header; }