Package org.springframework.http
Class ResponseCookie
- java.lang.Object
- org.springframework.http.HttpCookie
- org.springframework.http.ResponseCookie
public final class ResponseCookie extends HttpCookie
AnHttpCookiesubclass with the additional attributes allowed in the "Set-Cookie" response header. To build an instance use thefrom(java.lang.String, java.lang.String)static method.- Since:
- 5.0
- Author:
- Rossen Stoyanchev, Brian Clozel
- See Also:
- RFC 6265
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceResponseCookie.ResponseCookieBuilderA builder for a server-defined HttpCookie with attributes.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object other)static ResponseCookie.ResponseCookieBuilderfrom(String name, String value)Factory method to obtain a builder for a server-defined cookie that starts with a name-value pair and may also include attributes.static ResponseCookie.ResponseCookieBuilderfromClientResponse(String name, String value)Factory method to obtain a builder for a server-defined cookie.StringgetDomain()Return the cookie "Domain" attribute, ornullif not set.DurationgetMaxAge()Return the cookie "Max-Age" attribute in seconds.StringgetPath()Return the cookie "Path" attribute, ornullif not set.StringgetSameSite()Return the cookie "SameSite" attribute, ornullif not set.inthashCode()booleanisHttpOnly()Returntrueif the cookie has the "HttpOnly" attribute.booleanisSecure()Returntrueif the cookie has the "Secure" attribute.StringtoString()Methods inherited from class org.springframework.http.HttpCookie
getName, getValue
Method Detail
getMaxAge
public Duration getMaxAge()
Return the cookie "Max-Age" attribute in seconds.A positive value indicates when the cookie expires relative to the current time. A value of 0 means the cookie should expire immediately. A negative value means no "Max-Age" attribute in which case the cookie is removed when the browser is closed.
getDomain
@Nullable public String getDomain()
Return the cookie "Domain" attribute, ornullif not set.
isSecure
public boolean isSecure()
Returntrueif the cookie has the "Secure" attribute.
isHttpOnly
public boolean isHttpOnly()
Returntrueif the cookie has the "HttpOnly" attribute.
getSameSite
@Nullable public String getSameSite()
Return the cookie "SameSite" attribute, ornullif not set.This limits the scope of the cookie such that it will only be attached to same site requests if
"Strict"or cross-site requests if"Lax".- Since:
- 5.1
- See Also:
- RFC6265 bis
equals
public boolean equals(@Nullable Object other)
- Overrides:
equalsin classHttpCookie
hashCode
public int hashCode()
- Overrides:
hashCodein classHttpCookie
toString
public String toString()
- Overrides:
toStringin classHttpCookie
from
public static ResponseCookie.ResponseCookieBuilder from(String name, String value)
Factory method to obtain a builder for a server-defined cookie that starts with a name-value pair and may also include attributes.- Parameters:
name- the cookie namevalue- the cookie value- Returns:
- a builder to create the cookie with
fromClientResponse
public static ResponseCookie.ResponseCookieBuilder fromClientResponse(String name, String value)
Factory method to obtain a builder for a server-defined cookie. Unlikefrom(String, String)this option assumes input from a remote server, which can be handled more leniently, e.g. ignoring a empty domain name with double quotes.- Parameters:
name- the cookie namevalue- the cookie value- Returns:
- a builder to create the cookie with
- Since:
- 5.2.5