Fixed some code smells

This commit is contained in:
Rsl1122 2019-05-09 14:53:04 +03:00
parent 3e5a1ce793
commit 15535e2469
2 changed files with 9 additions and 15 deletions

View File

@ -35,17 +35,15 @@ public class RequestTarget {
resourceString = targetURI.getPath();
resource = Arrays.stream(resourceString.split("/")).filter(part -> !part.isEmpty()).collect(Collectors.toList());
String parameterString = targetURI.getQuery();
parameters = parseParameters(parameterString);
parameters = new TreeMap<>();
parseParameters(targetURI.getQuery());
}
private Map<String, String> parseParameters(String parameterString) {
private void parseParameters(String parameterString) {
if (parameterString == null || parameterString.isEmpty()) {
return Collections.emptyMap();
return;
}
TreeMap<String, String> parameters = new TreeMap<>();
String[] keysAndValues = parameterString.split("&");
for (String kv : keysAndValues) {
if (kv.isEmpty()) {
@ -56,8 +54,6 @@ public class RequestTarget {
parameters.put(keyAndValue[0], keyAndValue[1]);
}
}
return parameters;
}
public boolean isEmpty() {

View File

@ -139,13 +139,11 @@ public class ResponseHandler extends TreePageHandler {
}
boolean isNotInfoRequest = target.isEmpty() || !target.get(0).equals("info");
boolean isAuthRequired = webServer.get().isAuthRequired() && isNotInfoRequest;
if (isAuthRequired) {
if (!authentication.isPresent()) {
if (webServer.get().isUsingHTTPS()) {
return responseFactory.basicAuth();
} else {
return responseFactory.forbidden403();
}
if (isAuthRequired && !authentication.isPresent()) {
if (webServer.get().isUsingHTTPS()) {
return responseFactory.basicAuth();
} else {
return responseFactory.forbidden403();
}
}
PageHandler pageHandler = getPageHandler(target);