do not break if we do not have a host name for cookie domain

This commit is contained in:
Jörg Prante 2024-04-26 14:37:29 +02:00
parent 9baa804bc2
commit 54ce2c8074

View file

@ -137,7 +137,7 @@ public class OutgoingContextHandler implements HttpHandler {
PercentEncoder percentEncoder = PercentEncoders.getCookieEncoder(StandardCharsets.ISO_8859_1); PercentEncoder percentEncoder = PercentEncoders.getCookieEncoder(StandardCharsets.ISO_8859_1);
DefaultCookie cookie = new DefaultCookie(sessionCookieName, percentEncoder.encode(cookieValue)); DefaultCookie cookie = new DefaultCookie(sessionCookieName, percentEncoder.encode(cookieValue));
String domain = extractDomain(host); String domain = extractDomain(host);
if ("localhost".equals(domain)) { if (domain == null || "localhost".equals(domain)) {
logger.log(Level.WARNING, "localhost not set as a cookie domain"); logger.log(Level.WARNING, "localhost not set as a cookie domain");
} else { } else {
cookie.setDomain('.' + domain); cookie.setDomain('.' + domain);
@ -153,7 +153,7 @@ public class OutgoingContextHandler implements HttpHandler {
private Cookie createEmptyCookie(String host, String path) { private Cookie createEmptyCookie(String host, String path) {
DefaultCookie cookie = new DefaultCookie(sessionCookieName); DefaultCookie cookie = new DefaultCookie(sessionCookieName);
String domain = extractDomain(host); String domain = extractDomain(host);
if ("localhost".equals(domain)) { if (domain == null || "localhost".equals(domain)) {
logger.log(Level.WARNING, "localhost not set as a cookie domain"); logger.log(Level.WARNING, "localhost not set as a cookie domain");
} else { } else {
cookie.setDomain('.' + domain); cookie.setDomain('.' + domain);
@ -168,6 +168,9 @@ public class OutgoingContextHandler implements HttpHandler {
} }
private static String extractDomain(String fqdn) { private static String extractDomain(String fqdn) {
if (fqdn == null) {
return null;
}
if ("localhost".equals(fqdn)) { if ("localhost".equals(fqdn)) {
return fqdn; return fqdn;
} }