From ebb4314ab992c3b571088160ed9bceb767522cbc Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 6 May 2019 13:54:14 +0300 Subject: [PATCH] URL parameters now work --- .../djrapitops/plan/system/webserver/Request.java | 13 ++++++++----- .../plan/system/webserver/RequestTarget.java | 9 ++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/Request.java b/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/Request.java index 1ec705cf3..e0d7a2bd2 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/Request.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/Request.java @@ -21,6 +21,7 @@ import com.djrapitops.plan.system.webserver.auth.Authentication; import com.sun.net.httpserver.HttpExchange; import java.io.InputStream; +import java.net.URI; import java.util.Optional; /** @@ -32,7 +33,9 @@ import java.util.Optional; */ public class Request { private final String requestMethod; - private final String targetString; + + private URI requestURI; + private final HttpExchange exchange; private final String remoteAddress; private final Locale locale; @@ -40,7 +43,7 @@ public class Request { public Request(HttpExchange exchange, Locale locale) { this.requestMethod = exchange.getRequestMethod(); - this.targetString = exchange.getRequestURI().getPath(); + requestURI = exchange.getRequestURI(); remoteAddress = exchange.getRemoteAddress().getAddress().getHostAddress(); @@ -62,11 +65,11 @@ public class Request { } public String getTargetString() { - return targetString; + return requestURI.getPath() + '?' + requestURI.getQuery(); } public RequestTarget getTarget() { - return new RequestTarget(targetString); + return new RequestTarget(requestURI); } public InputStream getRequestBody() { @@ -75,7 +78,7 @@ public class Request { @Override public String toString() { - return "Request:" + requestMethod + " " + targetString; + return "Request:" + requestMethod + " " + requestURI.getPath(); } public String getRemoteAddress() { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/RequestTarget.java b/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/RequestTarget.java index 7fd887d73..5d182a3fc 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/RequestTarget.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/RequestTarget.java @@ -16,6 +16,7 @@ */ package com.djrapitops.plan.system.webserver; +import java.net.URI; import java.util.*; import java.util.stream.Collectors; @@ -30,13 +31,11 @@ public class RequestTarget { private final List resource; private final Map parameters; - public RequestTarget(String targetString) { - String[] resourceAndParameters = targetString.split("\\?", 2); - - resourceString = resourceAndParameters.length >= 1 ? resourceAndParameters[0] : "/"; + public RequestTarget(URI targetURI) { + resourceString = targetURI.getPath(); resource = Arrays.stream(resourceString.split("/")).filter(part -> !part.isEmpty()).collect(Collectors.toList()); - String parameterString = resourceAndParameters.length >= 2 ? resourceAndParameters[1] : null; + String parameterString = targetURI.getQuery(); parameters = parseParameters(parameterString); }