From 5996f7cba4ef2cb15e0f375377be69863d73988c Mon Sep 17 00:00:00 2001 From: Fuzzlemann Date: Sat, 12 Aug 2017 15:19:44 +0200 Subject: [PATCH] Removes unused Request class --- .../djrapitops/plan/ui/webserver/Request.java | 151 ------------------ 1 file changed, 151 deletions(-) delete mode 100644 Plan/src/main/java/com/djrapitops/plan/ui/webserver/Request.java diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Request.java b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Request.java deleted file mode 100644 index a0903f072..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Request.java +++ /dev/null @@ -1,151 +0,0 @@ -package main.java.com.djrapitops.plan.ui.webserver; - -import main.java.com.djrapitops.plan.Log; - -import java.io.*; -import java.util.Arrays; -import java.util.Optional; - -/** - * Represents a HTTP Request. - *

- * Request is read from the given InputStream. - *

- * Closing the Request closes the InputStream. (Closing Socket InputStream - * closes the socket.) - *

- * Request Strings should not be logged because they may contain base64 encoded - * user:password Authorization combinations. - * - * @author Rsl1122 - * @since 3.5.2 - */ -public class Request implements Closeable { - - private final InputStream input; - private String request; - private String target; - private String authorization; - - private Closeable close; - - /** - * Creates a new Request object. - * - * @param input InputStream to read the socket. - */ - public Request(InputStream input) { - this.input = input; - } - - /** - * Reads the information in the Request and parses required information. - *

- * Parses Request (GET, POST etc.) - *

- * Parses Target (/home/etc) - *

- * Parses Authorization (Authorization header). - * - * @throws java.io.IOException if InputStream can not be read. - */ - public void parse() throws IOException { - StringBuilder headerB = new StringBuilder(); - BufferedReader in = new BufferedReader(new InputStreamReader(input)); - close = in; - while (true) { - String line = in.readLine(); - if (line == null || line.isEmpty()) { - break; - } - headerB.append(line); - headerB.append(":::"); - } - final String requestHeader = headerB.toString(); - String[] header = requestHeader.split(":::"); - parseRequestAndTarget(header); - parseAuthorization(header); - } - - /** - * Check if the request has Authorization: Basic header. - * - * @return true/false - */ - public boolean hasAuthorization() { - return authorization != null; - } - - /** - * Returns the base64 encoded Authorization if present. - * - * @return base64 encoded user:password or null. - */ - public String getAuthorization() { - return authorization; - } - - private void parseAuthorization(String[] header) { - Optional auth = Arrays.stream(header) - .filter(l -> l.contains("Authorization: Basic ")) - .findFirst(); - if (auth.isPresent()) { - Log.debug("Found Authorization."); - authorization = auth.get().replace("Authorization: Basic ", ""); - } else { - Log.debug("Not Authorized."); - } - } - - private void parseRequestAndTarget(String[] header) { - String req = header[0]; - String[] reqLine = req.split(" "); - if (reqLine.length >= 2) { - request = reqLine[0]; - target = reqLine[1].replace("%20", " ") - .replace("%2E", "."); - } else { - request = "GET"; - target = "/"; - } - } - - /** - * Used to get the request type. - * - * @return GET, POST, etc. - */ - public String getRequest() { - return request; - } - - /** - * Used to get the target. - * - * @return for example '/home/etc' - */ - public String getTarget() { - return target; - } - - /** - * Closes the Request. - *

- * Closes the InputStream. - * - * @throws IOException if the stream can not be closed. - */ - @Override - public void close() throws IOException { - close.close(); - } - - @Override - public String toString() { - return "Request{" + - "request='" + request + '\'' + - ", target='" + target + '\'' + - ", authorization='" + authorization + '\'' + - '}'; - } -}