|
|
|
@ -4,11 +4,21 @@ package de.srsoftware.http;
@@ -4,11 +4,21 @@ package de.srsoftware.http;
|
|
|
|
|
|
|
|
|
|
import com.sun.net.httpserver.Headers; |
|
|
|
|
import com.sun.net.httpserver.HttpExchange; |
|
|
|
|
|
|
|
|
|
import java.time.Instant; |
|
|
|
|
import java.time.ZoneOffset; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class SessionToken extends Cookie { |
|
|
|
|
private final String sessionId; |
|
|
|
|
private static final DateTimeFormatter FORMAT = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss O"); |
|
|
|
|
|
|
|
|
|
public SessionToken(String sessionId, Instant expiration){ |
|
|
|
|
super("sessionToken", "%s; Path=/api; Expires=%s".formatted(sessionId,FORMAT.format(expiration.atZone(ZoneOffset.UTC)))); |
|
|
|
|
this.sessionId = sessionId; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public SessionToken(String sessionId) { |
|
|
|
|
super("sessionToken", sessionId + "; Path=/api"); |
|
|
|
@ -17,8 +27,8 @@ public class SessionToken extends Cookie {
@@ -17,8 +27,8 @@ public class SessionToken extends Cookie {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public <T extends Cookie> T addTo(Headers headers) { |
|
|
|
|
headers.add("session", sessionId); |
|
|
|
|
return (T)this; // super.addTo(headers);
|
|
|
|
|
headers.add("session", getValue()); |
|
|
|
|
return super.addTo(headers); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static Optional<SessionToken> from(HttpExchange ex) { |
|
|
|
|