mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-26 02:57:52 +01:00
URL parameters now work
This commit is contained in:
parent
799c26ba99
commit
ebb4314ab9
@ -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() {
|
||||
|
@ -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<String> resource;
|
||||
private final Map<String, String> 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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user