Class ServerCookieEncoder


  • public final class ServerCookieEncoder
    extends Object
    A RFC6265 compliant cookie encoder to be used server side, so some fields are sent (Version is typically ignored).

    As Netty's Cookie merges Expires and MaxAge into one single field, only Max-Age field is sent.

    Note that multiple cookies are supposed to be sent at once in a single "Set-Cookie" header.

    See Also:
    ServerCookieDecoder
    • Field Detail

      • STRICT

        public static final ServerCookieEncoder STRICT
        Strict encoder that validates that name and value chars are in the valid scope defined in RFC6265
      • LAX

        public static final ServerCookieEncoder LAX
        Lax instance that doesn't validate name and value
    • Method Detail

      • encode

        public String encode​(String name,
                             String value)
        Encodes the specified cookie name-value pair into a Set-Cookie header value.
        Parameters:
        name - the cookie name
        value - the cookie value
        Returns:
        a single Set-Cookie header value
      • encode

        public String encode​(Cookie cookie)
        Encodes the specified cookie into a Set-Cookie header value.
        Parameters:
        cookie - the cookie
        Returns:
        a single Set-Cookie header value
      • encode

        public List<String> encode​(Cookie... cookies)
        Batch encodes cookies into Set-Cookie header values.
        Parameters:
        cookies - a bunch of cookies
        Returns:
        the corresponding bunch of Set-Cookie headers
      • encode

        public List<String> encode​(Collection<? extends Cookie> cookies)
        Batch encodes cookies into Set-Cookie header values.
        Parameters:
        cookies - a bunch of cookies
        Returns:
        the corresponding bunch of Set-Cookie headers
      • encode

        public List<String> encode​(Iterable<? extends Cookie> cookies)
        Batch encodes cookies into Set-Cookie header values.
        Parameters:
        cookies - a bunch of cookies
        Returns:
        the corresponding bunch of Set-Cookie headers
      • validateCookie

        protected void validateCookie​(String name,
                                      String value)