Fixed authentication message showing '/'

This commit is contained in:
Rsl1122 2019-03-01 09:41:41 +02:00
parent 6806e6c98e
commit 75782562f9
2 changed files with 11 additions and 1 deletions

View File

@ -86,7 +86,7 @@ public class RequestHandler implements HttpHandler {
try { try {
Response response = responseHandler.getResponse(request); Response response = responseHandler.getResponse(request);
if (response instanceof PromptAuthorizationResponse) { 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); response.setResponseHeaders(responseHeaders);

View File

@ -25,6 +25,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
/** /**
@ -53,6 +54,15 @@ public abstract class Response {
return header; return header;
} }
public Optional<String> 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) { public void setHeader(String header) {
this.header = header; this.header = header;
} }