diff --git a/akka-http-core/src/main/java/akka/http/javadsl/model/headers/HttpCookie.java b/akka-http-core/src/main/java/akka/http/javadsl/model/headers/HttpCookie.java index 3faf0e266c..b7d1f2cc00 100644 --- a/akka-http-core/src/main/java/akka/http/javadsl/model/headers/HttpCookie.java +++ b/akka-http-core/src/main/java/akka/http/javadsl/model/headers/HttpCookie.java @@ -28,6 +28,14 @@ public abstract class HttpCookie { false, false, Util.scalaNone()); } + public static HttpCookie create(String name, String value, Option domain, Option path) { + return new akka.http.scaladsl.model.headers.HttpCookie( + name, value, + Util.scalaNone(), Util.scalaNone(), + domain.asScala(), path.asScala(), + false, false, + Util.scalaNone()); + } @SuppressWarnings("unchecked") public static HttpCookie create( String name, @@ -49,4 +57,39 @@ public abstract class HttpCookie { httpOnly, extension.asScala()); } + + /** + * Returns a copy of this HttpCookie instance with the given expiration set. + */ + public abstract HttpCookie withExpires(DateTime dateTime); + + /** + * Returns a copy of this HttpCookie instance with the given max age set. + */ + public abstract HttpCookie withMaxAge(long maxAge); + + /** + * Returns a copy of this HttpCookie instance with the given domain set. + */ + public abstract HttpCookie withDomain(String domain); + + /** + * Returns a copy of this HttpCookie instance with the given path set. + */ + public abstract HttpCookie withPath(String path); + + /** + * Returns a copy of this HttpCookie instance with the given secure flag set. + */ + public abstract HttpCookie withSecure(boolean secure); + + /** + * Returns a copy of this HttpCookie instance with the given http-only flag set. + */ + public abstract HttpCookie withHttpOnly(boolean httpOnly); + + /** + * Returns a copy of this HttpCookie instance with the given extension set. + */ + public abstract HttpCookie withExtension(String extension); } diff --git a/akka-http-core/src/main/scala/akka/http/scaladsl/model/headers/HttpCookie.scala b/akka-http-core/src/main/scala/akka/http/scaladsl/model/headers/HttpCookie.scala index 717b3c1feb..4c246544e6 100644 --- a/akka-http-core/src/main/scala/akka/http/scaladsl/model/headers/HttpCookie.scala +++ b/akka-http-core/src/main/scala/akka/http/scaladsl/model/headers/HttpCookie.scala @@ -4,6 +4,7 @@ package akka.http.scaladsl.model.headers +import akka.http.javadsl.model.headers import akka.parboiled2.CharPredicate import akka.japi.{ Option ⇒ JOption } import akka.http.scaladsl.model.DateTime @@ -77,6 +78,20 @@ final case class HttpCookie( def getMaxAge: JOption[java.lang.Long] = maxAge.asJava /** Java API */ def getExpires: JOption[jm.DateTime] = expires.asJava + /** Java API */ + def withExpires(dateTime: jm.DateTime): headers.HttpCookie = copy(expires = Some(dateTime.asScala)) + /** Java API */ + def withDomain(domain: String): headers.HttpCookie = copy(domain = Some(domain)) + /** Java API */ + def withPath(path: String): headers.HttpCookie = copy(path = Some(path)) + /** Java API */ + def withMaxAge(maxAge: Long): headers.HttpCookie = copy(maxAge = Some(maxAge)) + /** Java API */ + def withSecure(secure: Boolean): headers.HttpCookie = copy(secure = secure) + /** Java API */ + def withHttpOnly(httpOnly: Boolean): headers.HttpCookie = copy(httpOnly = httpOnly) + /** Java API */ + def withExtension(extension: String): headers.HttpCookie = copy(extension = Some(extension)) } object HttpCookie {