minor improvements
This commit is contained in:
@@ -3,7 +3,6 @@ package de.srsoftware.cookies;
|
|||||||
|
|
||||||
|
|
||||||
import com.sun.net.httpserver.HttpExchange;
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class SessionToken extends Cookie {
|
public class SessionToken extends Cookie {
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public abstract class PathHandler implements HttpHandler {
|
|||||||
String path = relativePath(ex);
|
String path = relativePath(ex);
|
||||||
String method = ex.getRequestMethod();
|
String method = ex.getRequestMethod();
|
||||||
System.out.printf("%s %s\n", method, path);
|
System.out.printf("%s %s\n", method, path);
|
||||||
boolean dummy = switch (method) {
|
boolean ignored = switch (method) {
|
||||||
case DELETE -> doDelete(path,ex);
|
case DELETE -> doDelete(path,ex);
|
||||||
case GET -> doGet(path,ex);
|
case GET -> doGet(path,ex);
|
||||||
case POST -> doPost(path,ex);
|
case POST -> doPost(path,ex);
|
||||||
@@ -89,11 +89,11 @@ public abstract class PathHandler implements HttpHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Optional<String> getHeader(HttpExchange ex, String key) {
|
public static Optional<String> getHeader(HttpExchange ex, String key) {
|
||||||
return Optional.ofNullable(ex.getRequestHeaders().get(key)).map(List::stream).map(Stream::findFirst).orElse(Optional.empty());
|
return Optional.ofNullable(ex.getRequestHeaders().get(key)).map(List::stream).flatMap(Stream::findFirst);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPost(String method) {
|
public static String hostname(HttpExchange ex) {
|
||||||
return POST.equals(method);
|
return "http://%s".formatted(ex.getRequestHeaders().getFirst("Host"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JSONObject json(HttpExchange ex) throws IOException {
|
public static JSONObject json(HttpExchange ex) throws IOException {
|
||||||
@@ -101,12 +101,7 @@ public abstract class PathHandler implements HttpHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Optional<String> language(HttpExchange ex) {
|
public static Optional<String> language(HttpExchange ex) {
|
||||||
return getHeader(ex, "Accept-Language").map(s -> Arrays.stream(s.split(","))).map(Stream::findFirst).orElse(Optional.empty());
|
return getHeader(ex, "Accept-Language").map(s -> Arrays.stream(s.split(","))).flatMap(Stream::findFirst);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static String prefix(HttpExchange ex) {
|
|
||||||
return "http://%s".formatted(ex.getRequestHeaders().getFirst("Host"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean sendEmptyResponse(int statusCode, HttpExchange ex) throws IOException {
|
public static boolean sendEmptyResponse(int statusCode, HttpExchange ex) throws IOException {
|
||||||
|
|||||||
@@ -165,10 +165,9 @@ public class Backend extends PathHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean openidConfig(HttpExchange ex) throws IOException {
|
private boolean openidConfig(HttpExchange ex) throws IOException {
|
||||||
var uri = ex.getRequestURI().toString();
|
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
|
|
||||||
json.put("authorization_endpoint", prefix(ex) + "/web/authorization.html");
|
json.put("authorization_endpoint", hostname(ex) + "/web/authorization.html");
|
||||||
return sendContent(ex, json);
|
return sendContent(ex, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user