INNER CODE UNIT · Java
addResponseCookie
pac4j/play-pac4j · shared/src/main/java/org/pac4j/play/PlayWebContext.java:207
public void addResponseCookie(final Cookie cookie) {
// Check if the cookie already exists in the request with the same value
final Optional<Http.Cookie> existingCookie = javaRequest.cookies().get(cookie.getName());
if (existingCookie.isPresent()) {
final Http.Cookie existing = existingCookie.get();
// If the cookie value hasn't changed, don't add it to response
if (existing.value().equals(cookie.getValue())) {
logger.trace("Skip adding response cookie {} as it already exists with same value", cookie.getName());
return;
}
}
final Http.CookieBuilder cookieBuilder =
Http.Cookie.builder(cookie.getName(), cookie.getValue())
.withPath(cookie.getPath())
.withDomain(cookie.getDomain())
.withSecure(cookie.isSecure())
.withHttpOnly(cookie.isHttpOnly());