+htc some convenience methods for javadsl.model.HttpCookie

This commit is contained in:
Johannes Rudolph 2015-06-12 16:41:14 +02:00
parent 446a616064
commit 31742b15ef
2 changed files with 58 additions and 0 deletions

View file

@ -28,6 +28,14 @@ public abstract class HttpCookie {
false, false, false, false,
Util.<String>scalaNone()); Util.<String>scalaNone());
} }
public static HttpCookie create(String name, String value, Option<String> domain, Option<String> path) {
return new akka.http.scaladsl.model.headers.HttpCookie(
name, value,
Util.<akka.http.scaladsl.model.DateTime>scalaNone(), Util.scalaNone(),
domain.asScala(), path.asScala(),
false, false,
Util.<String>scalaNone());
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static HttpCookie create( public static HttpCookie create(
String name, String name,
@ -49,4 +57,39 @@ public abstract class HttpCookie {
httpOnly, httpOnly,
extension.asScala()); 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);
} }

View file

@ -4,6 +4,7 @@
package akka.http.scaladsl.model.headers package akka.http.scaladsl.model.headers
import akka.http.javadsl.model.headers
import akka.parboiled2.CharPredicate import akka.parboiled2.CharPredicate
import akka.japi.{ Option JOption } import akka.japi.{ Option JOption }
import akka.http.scaladsl.model.DateTime import akka.http.scaladsl.model.DateTime
@ -77,6 +78,20 @@ final case class HttpCookie(
def getMaxAge: JOption[java.lang.Long] = maxAge.asJava def getMaxAge: JOption[java.lang.Long] = maxAge.asJava
/** Java API */ /** Java API */
def getExpires: JOption[jm.DateTime] = expires.asJava 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 { object HttpCookie {