Class ClientCookieEncoder


  • public final class ClientCookieEncoder
    extends CookieEncoder
    A RFC6265 compliant cookie encoder to be used client side, so only name=value pairs are sent. Note that multiple cookies are supposed to be sent at once in a single "Cookie" header.
     // Example
     HttpRequest req = ...;
     res.setHeader("Cookie", ClientCookieEncoder.encode("JSESSIONID", "1234"));
     
    See Also:
    ClientCookieDecoder
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static ClientCookieEncoder LAX
      Lax instance that doesn't validate name and value, and (for methods that accept multiple cookies) keeps cookies in the order in which they were given.
      static ClientCookieEncoder STRICT
      Strict encoder that validates that name and value chars are in the valid scope and (for methods that accept multiple cookies) sorts cookies into order of decreasing path length, as specified in RFC6265.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String encode​(Cookie cookie)
      Encodes the specified cookie into a Cookie header value.
      java.lang.String encode​(Cookie... cookies)
      Encodes the specified cookies into a single Cookie header value.
      java.lang.String encode​(java.lang.Iterable<? extends Cookie> cookies)
      Encodes the specified cookies into a single Cookie header value.
      java.lang.String encode​(java.lang.String name, java.lang.String value)
      Encodes the specified cookie into a Cookie header value.
      java.lang.String encode​(java.util.Collection<? extends Cookie> cookies)
      Encodes the specified cookies into a single Cookie header value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • STRICT

        public static final ClientCookieEncoder STRICT
        Strict encoder that validates that name and value chars are in the valid scope and (for methods that accept multiple cookies) sorts cookies into order of decreasing path length, as specified in RFC6265.
      • LAX

        public static final ClientCookieEncoder LAX
        Lax instance that doesn't validate name and value, and (for methods that accept multiple cookies) keeps cookies in the order in which they were given.
    • Method Detail

      • encode

        public java.lang.String encode​(java.lang.String name,
                                       java.lang.String value)
        Encodes the specified cookie into a Cookie header value.
        Parameters:
        name - the cookie name
        value - the cookie value
        Returns:
        a Rfc6265 style Cookie header value
      • encode

        public java.lang.String encode​(Cookie cookie)
        Encodes the specified cookie into a Cookie header value.
        Parameters:
        cookie - the specified cookie
        Returns:
        a Rfc6265 style Cookie header value
      • encode

        public java.lang.String encode​(Cookie... cookies)
        Encodes the specified cookies into a single Cookie header value.
        Parameters:
        cookies - some cookies
        Returns:
        a Rfc6265 style Cookie header value, null if no cookies are passed.
      • encode

        public java.lang.String encode​(java.util.Collection<? extends Cookie> cookies)
        Encodes the specified cookies into a single Cookie header value.
        Parameters:
        cookies - some cookies
        Returns:
        a Rfc6265 style Cookie header value, null if no cookies are passed.
      • encode

        public java.lang.String encode​(java.lang.Iterable<? extends Cookie> cookies)
        Encodes the specified cookies into a single Cookie header value.
        Parameters:
        cookies - some cookies
        Returns:
        a Rfc6265 style Cookie header value, null if no cookies are passed.