org.springframework.mock.web

Class MockCookie

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable


    public class MockCookie
    extends Cookie
    Extension of Cookie with extra directives, as defined in RFC 6265.
    Since:
    5.1
    Author:
    Vedran Pavic
    See Also:
    Serialized Form
    • Constructor Detail

      • MockCookie

        public MockCookie(java.lang.String name,
                          java.lang.String value)
        Constructor with the cookie name and value.
        Parameters:
        name - the name
        value - the value
        See Also:
        Cookie.Cookie(String, String)
    • Method Detail

      • setSameSite

        public void setSameSite(@Nullable
                                java.lang.String sameSite)
        Add the "SameSite" attribute to the cookie.

        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".

        See Also:
        RFC6265 bis
      • getSameSite

        @Nullable
        public java.lang.String getSameSite()
        Return the "SameSite" attribute, or null if not set.
      • parse

        public static MockCookie parse(java.lang.String setCookieHeader)
        Factory method that parses the value of a "Set-Cookie" header.
        Parameters:
        setCookieHeader - the "Set-Cookie" value
        Returns:
        the created cookie