java.lang.Object
org.eclipse.jetty.server.HttpCookieUtils
Utility methods for server-side HTTP cookie handling.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAHttpFieldthat holds anHttpHeader.SET_COOKIEas aHttpCookieinstance, delaying any value generation untilHttpCookieUtils.SetCookieHttpField.getValue()is called. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of context attribute with default SameSite cookie value -
Method Summary
Modifier and TypeMethodDescriptionstatic org.eclipse.jetty.http.HttpCookiecheckSameSite(org.eclipse.jetty.http.HttpCookie cookie, org.eclipse.jetty.util.Attributes attributes) Check that samesite is set on the cookie.extractBasics(String setCookieHeader) Extract the bare minimum of info from a Set-Cookie header string.static StringgetRFC2965SetCookie(org.eclipse.jetty.http.HttpCookie httpCookie) static StringgetRFC6265SetCookie(org.eclipse.jetty.http.HttpCookie httpCookie) static org.eclipse.jetty.http.HttpCookie.SameSitegetSameSiteDefault(org.eclipse.jetty.util.Attributes contextAttributes) Get the default value for SameSite cookie attribute, if one has been set for the given context.static StringgetSetCookie(org.eclipse.jetty.http.HttpCookie httpCookie, org.eclipse.jetty.http.CookieCompliance compliance) static org.eclipse.jetty.http.HttpCookiegetSetCookie(org.eclipse.jetty.http.HttpField field) Get aHttpHeader.SET_COOKIEfield as aHttpCookie, either by optimally checking for aHttpCookieUtils.SetCookieHttpFieldor by parsing the value withparseSetCookie(String).static booleanCheck if the Set-Cookie header represented as a string is for the name, domain and path given.static booleanCheck if the HttpCookie is for the given name, domain and path.static org.eclipse.jetty.http.HttpCookieparseSetCookie(String value)
-
Field Details
-
SAME_SITE_DEFAULT_ATTRIBUTE
Name of context attribute with default SameSite cookie value- See Also:
-
-
Method Details
-
checkSameSite
public static org.eclipse.jetty.http.HttpCookie checkSameSite(org.eclipse.jetty.http.HttpCookie cookie, org.eclipse.jetty.util.Attributes attributes) Check that samesite is set on the cookie. If not, use a context default value, if one has been set.- Parameters:
cookie- the cookie to checkattributes- the context to check settings- Returns:
- either the original cookie, or a new one that has the samesit default set
-
extractBasics
Extract the bare minimum of info from a Set-Cookie header string.Ideally this method should not be necessary, however as java.net.HttpCookie does not yet support generic attributes, we have to use it in a minimal fashion. When it supports attributes, we could look at reverting to a constructor on o.e.j.h.HttpCookie to take the set-cookie header string.
- Parameters:
setCookieHeader- the header as a string- Returns:
- a map containing the name, value, domain, path. max-age of the set cookie header
-
getSameSiteDefault
public static org.eclipse.jetty.http.HttpCookie.SameSite getSameSiteDefault(org.eclipse.jetty.util.Attributes contextAttributes) Get the default value for SameSite cookie attribute, if one has been set for the given context.- Parameters:
contextAttributes- the context to check for default SameSite value- Returns:
- the default SameSite value or null if one does not exist
- Throws:
IllegalStateException- if the default value is not a permitted value
-
getSetCookie
public static String getSetCookie(org.eclipse.jetty.http.HttpCookie httpCookie, org.eclipse.jetty.http.CookieCompliance compliance) -
getRFC2965SetCookie
-
getRFC6265SetCookie
-
match
Check if the Set-Cookie header represented as a string is for the name, domain and path given.- Parameters:
setCookieHeader- a Set-Cookie headername- the cookie name to checkdomain- the cookie domain to checkpath- the cookie path to check- Returns:
- true if all of the name, domain and path match the Set-Cookie header, false otherwise
-
match
public static boolean match(org.eclipse.jetty.http.HttpCookie cookie, String name, String domain, String path) Check if the HttpCookie is for the given name, domain and path.- Parameters:
cookie- the jetty HttpCookie to checkname- the cookie name to checkdomain- the cookie domain to checkpath- the cookie path to check- Returns:
- true if name, domain, and path, match all match the HttpCookie, false otherwise
-
getSetCookie
public static org.eclipse.jetty.http.HttpCookie getSetCookie(org.eclipse.jetty.http.HttpField field) Get aHttpHeader.SET_COOKIEfield as aHttpCookie, either by optimally checking for aHttpCookieUtils.SetCookieHttpFieldor by parsing the value withparseSetCookie(String).- Parameters:
field- The field- Returns:
- The field value as a
HttpCookieor null if the field is not aHttpHeader.SET_COOKIEor cannot be parsed.
-
parseSetCookie
-