Top Description Inners Fields Constructors Methods
org.eclipse.jetty.server

public final Class HttpCookieUtils

extends Object
Class Inheritance
Imports
java.time.Instant, java.util.List, .Locale, .Map, org.eclipse.jetty.http.ComplianceViolationException, .CookieCompliance, .HttpCookie, .HttpField, .HttpHeader, .Syntax, org.eclipse.jetty.util.Attributes, .Index, .QuotedStringTokenizer

Utility methods for server-side HTTP cookie handling.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
HttpCookieUtils.SetCookieHttpField

A HttpField that holds an HttpHeader#SET_COOKIE as a HttpCookie instance, delaying any value generation until getValue() is called.

Field Summary

Modifier and TypeField and Description
private static final String
private static final Index<String>
public static final String
SAME_SITE_DEFAULT_ATTRIBUTE

Name of context attribute with default SameSite cookie value

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static HttpCookie

Returns:

either the original cookie, or a new one that has the samesit default set
checkSameSite
(HttpCookie
the cookie to check
cookie
,
Attributes
the context to check settings
attributes
)

Check that samesite is set on the cookie.

public static String
public static String
public static HttpCookie.SameSite

Returns:

the default SameSite value or null if one does not exist
getSameSiteDefault
(Attributes
the context to check for default SameSite value
contextAttributes
)

Get the default value for SameSite cookie attribute, if one has been set for the given context.

public static String
getSetCookie(HttpCookie httpCookie, CookieCompliance compliance)

private static boolean

Returns:

whether the text needs to be quoted
isQuoteNeeded
(String
the text to check
text
)

Whether a cookie name/value/attribute needs to be quoted.

public static boolean

Returns:

true if all of the name, domain and path match the Set-Cookie header, false otherwise
match
(String
a Set-Cookie header
setCookieHeader
,
String
the cookie name to check
name
,
String
the cookie domain to check
domain
,
String
the cookie path to check
path
)

Check if the Set-Cookie header represented as a string is for the name, domain and path given.

public static boolean

Returns:

true if name, domain, and path, match all match the HttpCookie, false otherwise
match
(HttpCookie
the jetty HttpCookie to check
cookie
,
String
the cookie name to check
name
,
String
the cookie domain to check
domain
,
String
the cookie path to check
path
)

Check if the HttpCookie is for the given name, domain and path.

private static boolean

Returns:

true if old and new names match exactly and the old and new domains match case-insensitively and the paths match exactly
match
(String oldName, String oldDomain, String oldPath, String newName, String newDomain, String newPath)

Check if all old parameters match the new parameters.

private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EPOCH_EXPIRESback to summary
private static final String EPOCH_EXPIRES
KNOWN_ATTRIBUTESback to summary
private static final Index<String> KNOWN_ATTRIBUTES
SAME_SITE_DEFAULT_ATTRIBUTEback to summary
public static final String SAME_SITE_DEFAULT_ATTRIBUTE

Name of context attribute with default SameSite cookie value

Constructor Detail

HttpCookieUtilsback to summary
private HttpCookieUtils()

Method Detail

checkSameSiteback to summary
public static HttpCookie checkSameSite(HttpCookie cookie, Attributes attributes)

Check that samesite is set on the cookie. If not, use a context default value, if one has been set.

Parameters
cookie:HttpCookie

the cookie to check

attributes:Attributes

the context to check settings

Returns:HttpCookie

either the original cookie, or a new one that has the samesit default set

getRFC2965SetCookieback to summary
public static String getRFC2965SetCookie(HttpCookie httpCookie)
getRFC6265SetCookieback to summary
public static String getRFC6265SetCookie(HttpCookie httpCookie)
getSameSiteDefaultback to summary
public static HttpCookie.SameSite getSameSiteDefault(Attributes contextAttributes)

Get the default value for SameSite cookie attribute, if one has been set for the given context.

Parameters
contextAttributes:Attributes

the context to check for default SameSite value

Returns:HttpCookie.SameSite

the default SameSite value or null if one does not exist

Exceptions
IllegalStateException:
if the default value is not a permitted value
getSetCookieback to summary
public static String getSetCookie(HttpCookie httpCookie, CookieCompliance compliance)
isQuoteNeededback to summary
private static boolean isQuoteNeeded(String text)

Whether a cookie name/value/attribute needs to be quoted.

Parameters
text:String

the text to check

Returns:boolean

whether the text needs to be quoted

Exceptions
IllegalArgumentException:
if the text contains illegal characters
matchback to summary
public static boolean match(String setCookieHeader, String name, String domain, String path)

Check if the Set-Cookie header represented as a string is for the name, domain and path given.

Parameters
setCookieHeader:String

a Set-Cookie header

name:String

the cookie name to check

domain:String

the cookie domain to check

path:String

the cookie path to check

Returns:boolean

true if all of the name, domain and path match the Set-Cookie header, false otherwise

matchback to summary
public static boolean match(HttpCookie cookie, String name, String domain, String path)

Check if the HttpCookie is for the given name, domain and path.

Parameters
cookie:HttpCookie

the jetty HttpCookie to check

name:String

the cookie name to check

domain:String

the cookie domain to check

path:String

the cookie path to check

Returns:boolean

true if name, domain, and path, match all match the HttpCookie, false otherwise

matchback to summary
private static boolean match(String oldName, String oldDomain, String oldPath, String newName, String newDomain, String newPath)

Check if all old parameters match the new parameters.

Returns:boolean

true if old and new names match exactly and the old and new domains match case-insensitively and the paths match exactly

quoteIfNeededAndAppendback to summary
private static void quoteIfNeededAndAppend(String text, StringBuilder builder)
org.eclipse.jetty.server back to summary

public Class HttpCookieUtils.SetCookieHttpField

extends HttpField
Class Inheritance

A HttpField that holds an HttpHeader#SET_COOKIE as a HttpCookie instance, delaying any value generation until getValue() is called.

Field Summary

Modifier and TypeField and Description
private final HttpCookie
private final String
Inherited from org.eclipse.jetty.http.HttpField:
NAME_VALUE_TOKENIZERPARAMETER_TOKENIZER

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public HttpCookie
public String
getValue()

Overrides org.eclipse.jetty.http.HttpField.getValue.

Get the field value.
Inherited from org.eclipse.jetty.http.HttpField:
containscontainscontainsLastcontainsLastequalsgetHeadergetIntValuegetLongValuegetLowerCaseNamegetNamegetValueListgetValueParametersgetValueshashCodeisisSameNamestripParameterstoStringvalueParameters

Field Detail

_valueback to summary
private final String _value

Hides org.eclipse.jetty.http.HttpField._value.

Constructor Detail

SetCookieHttpFieldback to summary
public SetCookieHttpField(HttpCookie cookie, CookieCompliance compliance)

Method Detail

getHttpCookieback to summary
public HttpCookie getHttpCookie()
getValueback to summary
public String getValue()

Overrides org.eclipse.jetty.http.HttpField.getValue.

Doc from org.eclipse.jetty.http.HttpField.getValue.

Get the field value.

Returns:String

the field value

Annotations
@Override