Class ResponseCookieImpl

java.lang.Object
org.refcodes.struct.RelationImpl<String,​String>
org.refcodes.struct.PropertyImpl
org.refcodes.struct.PropertyImpl.PropertyBuilderImpl
org.refcodes.web.ResponseCookieImpl
All Implemented Interfaces:
org.refcodes.mixin.DomainAccessor, org.refcodes.mixin.DomainAccessor.DomainBuilder<ResponseCookie>, org.refcodes.mixin.DomainAccessor.DomainMutator, org.refcodes.mixin.DomainAccessor.DomainProperty, org.refcodes.mixin.KeyAccessor<String>, org.refcodes.mixin.KeyAccessor.KeyBuilder<String,​org.refcodes.struct.Relation.RelationBuilder<String,​String>>, org.refcodes.mixin.KeyAccessor.KeyMutator<String>, org.refcodes.mixin.KeyAccessor.KeyProperty<String>, org.refcodes.mixin.PathAccessor, org.refcodes.mixin.PathAccessor.PathBuilder<ResponseCookie>, org.refcodes.mixin.PathAccessor.PathMutator, org.refcodes.mixin.PathAccessor.PathProperty, org.refcodes.mixin.ValueAccessor<String>, org.refcodes.mixin.ValueAccessor.ValueBuilder<String,​org.refcodes.struct.Relation.RelationBuilder<String,​String>>, org.refcodes.mixin.ValueAccessor.ValueMutator<String>, org.refcodes.mixin.ValueAccessor.ValueProperty<String>, org.refcodes.struct.Property, org.refcodes.struct.Property.PropertyBuilder, org.refcodes.struct.Relation<String,​String>, org.refcodes.struct.Relation.RelationBuilder<String,​String>, Cookie, ResponseCookie

public class ResponseCookieImpl
extends org.refcodes.struct.PropertyImpl.PropertyBuilderImpl
implements ResponseCookie
As of "HTTP cookies explained - NCZOnline": "... There is some confusion over encoding of a cookie value. The commonly held belief is that cookie values must be URL-encoded, but this is a fallacy even though it is the de facto implementation. The original specification indicates that only three types of characters must be encoded: semicolon, comma, and white space. The specification indicates that URL encoding may be used but stops short of requiring it. The RFC makes no mention of encoding whatsoever. Still, almost all implementations perform some sort of URL encoding on cookie values. In the case of name=value formats, the name and value are typically encoded separately while the equals sign is left as is. ..." Therefore we use URL encoding to make life easier and not fall into the trap of unescaped values.
See Also:
"https://www.nczonline.net/blog/2009/05/05/http-cookies-explained"
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.refcodes.struct.PropertyImpl

    org.refcodes.struct.PropertyImpl.PropertyBuilderImpl

    Nested classes/interfaces inherited from class org.refcodes.struct.RelationImpl

    org.refcodes.struct.RelationImpl.RelationBuilderImpl<K extends Object,​V extends Object>

    Nested classes/interfaces inherited from interface org.refcodes.mixin.DomainAccessor

    org.refcodes.mixin.DomainAccessor.DomainBuilder<B extends org.refcodes.mixin.DomainAccessor.DomainBuilder<?>>, org.refcodes.mixin.DomainAccessor.DomainMutator, org.refcodes.mixin.DomainAccessor.DomainProperty

    Nested classes/interfaces inherited from interface org.refcodes.mixin.KeyAccessor

    org.refcodes.mixin.KeyAccessor.KeyBuilder<K extends Object,​B extends org.refcodes.mixin.KeyAccessor.KeyBuilder<K,​B>>, org.refcodes.mixin.KeyAccessor.KeyMutator<K extends Object>, org.refcodes.mixin.KeyAccessor.KeyProperty<K extends Object>

    Nested classes/interfaces inherited from interface org.refcodes.mixin.PathAccessor

    org.refcodes.mixin.PathAccessor.PathBuilder<B extends org.refcodes.mixin.PathAccessor.PathBuilder<?>>, org.refcodes.mixin.PathAccessor.PathMutator, org.refcodes.mixin.PathAccessor.PathProperty

    Nested classes/interfaces inherited from interface org.refcodes.struct.Property

    org.refcodes.struct.Property.PropertyBuilder

    Nested classes/interfaces inherited from interface org.refcodes.struct.Relation

    org.refcodes.struct.Relation.RelationBuilder<K extends Object,​V extends Object>

    Nested classes/interfaces inherited from interface org.refcodes.mixin.ValueAccessor

    org.refcodes.mixin.ValueAccessor.ValueBuilder<V extends Object,​B extends org.refcodes.mixin.ValueAccessor.ValueBuilder<V,​B>>, org.refcodes.mixin.ValueAccessor.ValueMutator<V extends Object>, org.refcodes.mixin.ValueAccessor.ValueProperty<V extends Object>
  • Field Summary

    Fields inherited from class org.refcodes.struct.RelationImpl

    _key, _value
  • Constructor Summary

    Constructors
    Constructor Description
    ResponseCookieImpl()
    Instantiates a new response cookie impl.
    ResponseCookieImpl​(String aHttpCookie)
    Constructs a ResponseCookie from the given HTTP cookie.
    ResponseCookieImpl​(String aCookieName, String aValue)
    Constructs a ResponseCookie.
    ResponseCookieImpl​(String aCookieName, String aValue, int aMaxAge, String aDomain, String aPath, boolean isSecure, boolean isHttpOnly, String aVersion)
    Constructs a ResponseCookie.
    ResponseCookieImpl​(String aCookieName, String aValue, Date aExpiresDate, String aDomain, String aPath, boolean isSecure, boolean isHttpOnly, String aVersion)
    Constructs a ResponseCookie.
    ResponseCookieImpl​(Cookie aCookie)
    Constructs a ResponseCookie.
  • Method Summary

    Modifier and Type Method Description
    String getDomain()
    Date getExpiresDate()
    Returns the expiration date of this cookie.
    int getMaxAge()
    Returns the Max-Age (seconds) for this cookie.
    String getPath()
    String getVersion()
    Returns the version this cookie.
    boolean isHttpOnly()
    Returns true if we have an HTTP only cookie.
    boolean isSecure()
    Returns true if we have a secure HTTP cookie.
    void setDomain​(String aDomain)
    void setExpiresAfter​(org.refcodes.time.TimeUnit aTimeUnit, long aTime)
    Sets the expires date to the current time plus the provided time.
    void setExpiresDate​(Date aExpireDate)
    Sets the expiration date of this cookie.
    void setHttpOnly​(boolean isHttpOnly)
    Sets whether it be an HTTP only cookie.
    void setMaxAge​(int aMaxAge)
    Sets the Max-Age (seconds) of this cookie.
    void setPath​(String aPath)
    void setSecure​(boolean isSecure)
    Sets whether it be a secure HTTP cookie.
    void setVersion​(String aVersion)
    Sets the version of this cookie.
    String toString()

    Methods inherited from class org.refcodes.struct.PropertyImpl.PropertyBuilderImpl

    setKey, setValue

    Methods inherited from class org.refcodes.struct.RelationImpl

    getKey, getValue

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.refcodes.mixin.DomainAccessor.DomainProperty

    letDomain

    Methods inherited from interface org.refcodes.mixin.KeyAccessor

    getKey

    Methods inherited from interface org.refcodes.mixin.KeyAccessor.KeyMutator

    setKey

    Methods inherited from interface org.refcodes.mixin.KeyAccessor.KeyProperty

    letKey

    Methods inherited from interface org.refcodes.mixin.PathAccessor.PathProperty

    letPath

    Methods inherited from interface org.refcodes.struct.Property

    toProperty

    Methods inherited from interface org.refcodes.struct.Property.PropertyBuilder

    withKey, withValue

    Methods inherited from interface org.refcodes.mixin.ValueAccessor

    getValue, getValueOr

    Methods inherited from interface org.refcodes.mixin.ValueAccessor.ValueMutator

    setValue

    Methods inherited from interface org.refcodes.mixin.ValueAccessor.ValueProperty

    letValue
  • Constructor Details

    • ResponseCookieImpl

      public ResponseCookieImpl()
      Instantiates a new response cookie impl.
    • ResponseCookieImpl

      public ResponseCookieImpl​(String aCookieName, String aValue)
      Constructs a ResponseCookie.
      Parameters:
      aCookieName - The name of the cookie.
      aValue - The value for the cookie.
    • ResponseCookieImpl

      public ResponseCookieImpl​(String aHttpCookie)
      Constructs a ResponseCookie from the given HTTP cookie.
      Parameters:
      aHttpCookie - The text as being found in the according HTTP header field.
    • ResponseCookieImpl

      public ResponseCookieImpl​(Cookie aCookie)
      Constructs a ResponseCookie.
      Parameters:
      aCookie - The Cookie from which to take the data.
    • ResponseCookieImpl

      public ResponseCookieImpl​(String aCookieName, String aValue, Date aExpiresDate, String aDomain, String aPath, boolean isSecure, boolean isHttpOnly, String aVersion)
      Constructs a ResponseCookie.
      Parameters:
      aCookieName - The name for the cookie
      aValue - The value of the cookie
      aExpiresDate - The expiration date of the cookie
      aDomain - The domain of the cookie
      aPath - The path of the cookie
      isSecure - The secure flag of the cookie
      isHttpOnly - The HTTP-only flag of the cookie
      aVersion - The version of the cookie.
    • ResponseCookieImpl

      public ResponseCookieImpl​(String aCookieName, String aValue, int aMaxAge, String aDomain, String aPath, boolean isSecure, boolean isHttpOnly, String aVersion)
      Constructs a ResponseCookie.
      Parameters:
      aCookieName - The name for the cookie
      aValue - The value of the cookie
      aMaxAge - Sets the Max-Age (seconds) of this cookie.
      aDomain - The domain of the cookie
      aPath - The path of the cookie
      isSecure - The secure flag of the cookie
      isHttpOnly - The HTTP-only flag of the cookie
      aVersion - The version of the cookie.
  • Method Details

    • getMaxAge

      public int getMaxAge()
      Returns the Max-Age (seconds) for this cookie.
      Specified by:
      getMaxAge in interface ResponseCookie
      Returns:
      The Max-Age.
    • setMaxAge

      public void setMaxAge​(int aMaxAge)
      Sets the Max-Age (seconds) of this cookie.
      Specified by:
      setMaxAge in interface ResponseCookie
      Parameters:
      aMaxAge - Sets the Max-Age.
    • getVersion

      public String getVersion()
      Returns the version this cookie.
      Specified by:
      getVersion in interface ResponseCookie
      Returns:
      The version.
    • setVersion

      public void setVersion​(String aVersion)
      Sets the version of this cookie.
      Specified by:
      setVersion in interface ResponseCookie
      Parameters:
      aVersion - Sets the version.
    • getPath

      public String getPath()
      Specified by:
      getPath in interface org.refcodes.mixin.PathAccessor
    • setPath

      public void setPath​(String aPath)
      Specified by:
      setPath in interface org.refcodes.mixin.PathAccessor.PathMutator
    • getExpiresDate

      public Date getExpiresDate()
      Returns the expiration date of this cookie.
      Specified by:
      getExpiresDate in interface ResponseCookie
      Returns:
      The expiration date.
    • setExpiresDate

      public void setExpiresDate​(Date aExpireDate)
      Sets the expiration date of this cookie.
      Specified by:
      setExpiresDate in interface ResponseCookie
      Parameters:
      aExpireDate - The expiration date.
    • getDomain

      public String getDomain()
      Specified by:
      getDomain in interface org.refcodes.mixin.DomainAccessor
    • setDomain

      public void setDomain​(String aDomain)
      Specified by:
      setDomain in interface org.refcodes.mixin.DomainAccessor.DomainMutator
    • setSecure

      public void setSecure​(boolean isSecure)
      Sets whether it be a secure HTTP cookie. Such a cookie only be transferred via HTTPS.
      Specified by:
      setSecure in interface ResponseCookie
      Parameters:
      isSecure - True in case of being a secure only cookie.
    • isSecure

      public boolean isSecure()
      Returns true if we have a secure HTTP cookie. Such a cookie only be transferred via HTTPS.
      Specified by:
      isSecure in interface ResponseCookie
      Returns:
      True in case of being a secure only cookie.
    • isHttpOnly

      public boolean isHttpOnly()
      Returns true if we have an HTTP only cookie. Such a cookie cannot be accessed client-side (via JavaScript).
      Specified by:
      isHttpOnly in interface ResponseCookie
      Returns:
      True in case of being an HTTP only cookie.
    • setHttpOnly

      public void setHttpOnly​(boolean isHttpOnly)
      Sets whether it be an HTTP only cookie. Such a cookie cannot be accessed client-side (via JavaScript).
      Specified by:
      setHttpOnly in interface ResponseCookie
      Parameters:
      isHttpOnly - True in case of being an HTTP only cookie.
    • setExpiresAfter

      public void setExpiresAfter​(org.refcodes.time.TimeUnit aTimeUnit, long aTime)
      Sets the expires date to the current time plus the provided time. Use ResponseCookie.getExpiresDate() to retrieve the resulting effective Date.
      Specified by:
      setExpiresAfter in interface ResponseCookie
      Parameters:
      aTimeUnit - The TimeUnit of the provided time
      aTime - The provided time after which to expire
    • toString

      public String toString()
      Overrides:
      toString in class org.refcodes.struct.PropertyImpl.PropertyBuilderImpl