|
|
|
@ -1,9 +1,6 @@
@@ -1,9 +1,6 @@
|
|
|
|
|
/* © SRSoftware 2024 */ |
|
|
|
|
package de.srsoftware.cookies; |
|
|
|
|
|
|
|
|
|
import static java.lang.System.Logger.Level.ERROR; |
|
|
|
|
import static java.lang.System.Logger.Level.WARNING; |
|
|
|
|
|
|
|
|
|
import com.sun.net.httpserver.Headers; |
|
|
|
|
import com.sun.net.httpserver.HttpExchange; |
|
|
|
|
import java.util.Arrays; |
|
|
|
@ -11,6 +8,8 @@ import java.util.List;
@@ -11,6 +8,8 @@ import java.util.List;
|
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
import static java.lang.System.Logger.Level.*; |
|
|
|
|
|
|
|
|
|
public abstract class Cookie implements Map.Entry<String, String> { |
|
|
|
|
static final System.Logger LOG = System.getLogger(SessionToken.class.getSimpleName()); |
|
|
|
|
private final String key; |
|
|
|
@ -22,7 +21,7 @@ public abstract class Cookie implements Map.Entry<String, String> {
@@ -22,7 +21,7 @@ public abstract class Cookie implements Map.Entry<String, String> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public <T extends Cookie> T addTo(Headers headers) { |
|
|
|
|
LOG.log(ERROR, "sending cookie {0}={1}", key, value); |
|
|
|
|
LOG.log(INFO, "sending cookie {0}={1}", key, value); |
|
|
|
|
headers.add("Set-Cookie", "%s=%s".formatted(key, value)); |
|
|
|
|
return (T)this; |
|
|
|
|
} |
|
|
|
@ -42,7 +41,7 @@ public abstract class Cookie implements Map.Entry<String, String> {
@@ -42,7 +41,7 @@ public abstract class Cookie implements Map.Entry<String, String> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected static List<String> of(HttpExchange ex) { |
|
|
|
|
return Optional.ofNullable(ex.getRequestHeaders().get("Cookie")).stream().flatMap(List::stream).flatMap(s -> Arrays.stream(s.split(";"))).map(String::trim).peek(cookie -> LOG.log(WARNING, "received cookie {0}", cookie)).toList(); |
|
|
|
|
return Optional.ofNullable(ex.getRequestHeaders().get("Cookie")).stream().flatMap(List::stream).flatMap(s -> Arrays.stream(s.split(";"))).map(String::trim).peek(cookie -> LOG.log(INFO, "received cookie {0}", cookie)).toList(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|