working on user login
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -4,10 +4,16 @@ package de.srsoftware.oidc.api;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class PathHandler implements HttpHandler {
|
||||
private String path;
|
||||
|
||||
|
||||
public class Bond {
|
||||
Bond(String p) {
|
||||
path = p;
|
||||
@@ -28,4 +34,17 @@ public abstract class PathHandler implements HttpHandler {
|
||||
if (path.startsWith("/")) path = path.substring(1);
|
||||
return path;
|
||||
}
|
||||
|
||||
public Optional<String> getHeader(HttpExchange ex, String key) {
|
||||
return Optional.ofNullable(ex.getRequestHeaders().get(key)).map(List::stream).map(Stream::findFirst).orElse(Optional.empty());
|
||||
}
|
||||
|
||||
public Optional<String> language(HttpExchange ex) {
|
||||
return getHeader(ex, "Accept-Language").map(s -> Arrays.stream(s.split(","))).map(Stream::findFirst).orElse(Optional.empty());
|
||||
}
|
||||
|
||||
public void emptyResponse(int statusCode, HttpExchange ex) throws IOException {
|
||||
ex.sendResponseHeaders(statusCode, 0);
|
||||
ex.getResponseBody().close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user