Package org.springframework.mock.web
Class MockCookie
- java.lang.Object
- javax.servlet.http.Cookie
- org.springframework.mock.web.MockCookie
- All Implemented Interfaces:
Serializable
,Cloneable
public class MockCookie extends Cookie
Extension ofCookie
with extra attributes, as defined in RFC 6265.- Since:
- 5.1
- Author:
- Vedran Pavic, Juergen Hoeller, Sam Brannen
- See Also:
- Serialized Form
Constructor Summary
Constructors Constructor Description MockCookie(String name, String value)
Construct a newMockCookie
with the supplied name and value.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ZonedDateTime
getExpires()
Get the "Expires" attribute for this cookie.String
getSameSite()
Get the "SameSite" attribute for this cookie.static MockCookie
parse(String setCookieHeader)
Factory method that parses the value of the supplied "Set-Cookie" header.void
setExpires(ZonedDateTime expires)
Set the "Expires" attribute for this cookie.void
setSameSite(String sameSite)
Set the "SameSite" attribute for this cookie.Methods inherited from class javax.servlet.http.Cookie
clone, getComment, getDomain, getMaxAge, getName, getPath, getSecure, getValue, getVersion, isHttpOnly, setComment, setDomain, setHttpOnly, setMaxAge, setPath, setSecure, setValue, setVersion
Constructor Detail
MockCookie
public MockCookie(String name, String value)
Construct a newMockCookie
with the supplied name and value.- Parameters:
name
- the namevalue
- the value- See Also:
Cookie(String, String)
Method Detail
setExpires
public void setExpires(@Nullable ZonedDateTime expires)
Set the "Expires" attribute for this cookie.- Since:
- 5.1.11
getExpires
@Nullable public ZonedDateTime getExpires()
Get the "Expires" attribute for this cookie.- Returns:
- the "Expires" attribute for this cookie, or
null
if not set - Since:
- 5.1.11
setSameSite
public void setSameSite(@Nullable String sameSite)
Set the "SameSite" attribute for this cookie.This limits the scope of the cookie such that it will only be attached to same-site requests if the supplied value is
"Strict"
or cross-site requests if the supplied value is"Lax"
.- See Also:
- RFC6265 bis
getSameSite
@Nullable public String getSameSite()
Get the "SameSite" attribute for this cookie.- Returns:
- the "SameSite" attribute for this cookie, or
null
if not set
parse
public static MockCookie parse(String setCookieHeader)
Factory method that parses the value of the supplied "Set-Cookie" header.- Parameters:
setCookieHeader
- the "Set-Cookie" value; nevernull
or empty- Returns:
- the created cookie