Class ResponseCookie

All Implemented Interfaces:
DomainAccessor, DomainAccessor.DomainBuilder<ResponseCookie>, DomainAccessor.DomainMutator, DomainAccessor.DomainProperty, KeyAccessor<String>, KeyAccessor.KeyBuilder<String, Relation.RelationBuilder<String,String>>, KeyAccessor.KeyMutator<String>, KeyAccessor.KeyProperty<String>, PathAccessor<String>, PathAccessor.PathBuilder<String, ResponseCookie>, PathAccessor.PathMutator<String>, PathAccessor.PathProperty<String>, ValueAccessor<String>, ValueAccessor.ValueBuilder<String, Relation.RelationBuilder<String,String>>, ValueAccessor.ValueMutator<String>, ValueAccessor.ValueProperty<String>, Property, Property.PropertyBuilder, Relation<String,String>, Relation.RelationBuilder<String,String>, Cookie

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.

The ResponseCookie represents response cookies: We use URL encoding / decoding for the cookie value (regarding fromHttpCookie(String) and toHttpCookie()) 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"
  • Constructor Details

    • ResponseCookie

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

      public ResponseCookie(String aCookieName, String aValue)
      Instantiates the class ResponseCookie.
      See Also:
    • ResponseCookie

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

      public ResponseCookie(Cookie aCookie)
      Instantiates the class ResponseCookie.
      Parameters:
      aCookie - The Cookie from which to take the data.
      See Also:
    • ResponseCookie

      public ResponseCookie(String aCookieName, String aValue, Date aExpiresDate, String aDomain, String aPath, boolean isSecure, boolean isHttpOnly, String aVersion)
      Instantiates the class ResponseCookie.
      Parameters:
      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.
      See Also:
    • ResponseCookie

      public ResponseCookie(String aCookieName, String aValue, int aMaxAge, String aDomain, String aPath, boolean isSecure, boolean isHttpOnly, String aVersion)
      Instantiates the class ResponseCookie.
      Parameters:
      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.
      See Also:
  • Method Details

    • getMaxAge

      public int getMaxAge()
      Returns the Max-Age (seconds) for this cookie.
      Returns:
      The Max-Age.
    • setMaxAge

      public void setMaxAge(int aMaxAge)
      Sets the Max-Age (seconds) of this cookie.
      Parameters:
      aMaxAge - Sets the Max-Age.
    • getVersion

      public String getVersion()
      Returns the version this cookie.
      Returns:
      The version.
    • setVersion

      public void setVersion(String aVersion)
      Sets the version of this cookie.
      Parameters:
      aVersion - Sets the version.
    • getPath

      public String getPath()
      Specified by:
      getPath in interface PathAccessor<String>
    • setPath

      public void setPath(String aPath)
      Specified by:
      setPath in interface PathAccessor.PathMutator<String>
    • getExpiresDate

      public Date getExpiresDate()
      Returns the expiration date of this cookie.
      Returns:
      The expiration date.
    • setExpiresDate

      public void setExpiresDate(Date aExpireDate)
      Sets the expiration date of this cookie.
      Parameters:
      aExpireDate - The expiration date.
    • getDomain

      public String getDomain()
      Specified by:
      getDomain in interface DomainAccessor
    • setDomain

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

      public void setSecure(boolean isSecure)
      Sets whether it be a secure HTTP cookie. Such a cookie only be transferred via HTTPS.
      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.
      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).
      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).
      Parameters:
      isHttpOnly - True in case of being an HTTP only cookie.
    • setExpiresAfter

      public void setExpiresAfter(TimeUnit aTimeUnit, long aTime)
      Sets the expires date to the current time plus the provided time. Use getExpiresDate() to retrieve the resulting effective Date.
      Parameters:
      aTimeUnit - The TimeUnit of the provided time
      aTime - The provided time after which to expire
    • withExpiresDate

      public ResponseCookie withExpiresDate(Date aExpiresDate)
      Sets the expiration date of this cookie and returns this instance as of the Builder-Pattern.
      Parameters:
      aExpiresDate - the expires date
      Returns:
      This instance as of the Builder-Pattern.
    • withPath

      public ResponseCookie withPath(String aPath)
      Sets the path of the cookie.
      Specified by:
      withPath in interface PathAccessor.PathBuilder<String, ResponseCookie>
    • withDomain

      public ResponseCookie withDomain(String aDomain)
      Sets the domain for this cookie.
      Specified by:
      withDomain in interface DomainAccessor.DomainBuilder<ResponseCookie>
    • withHttpOnly

      public ResponseCookie withHttpOnly(boolean isHttpOnly)
      Sets whether it be an HTTP only cookie. Such a cookie cannot be accessed client-side (via JavaScript). Returns this instance as of the builder pattern.
      Parameters:
      isHttpOnly - True in case of being an HTTP only cookie.
      Returns:
      Returns this instance as of the Builder-Pattern.
    • withExpiresAfter

      public ResponseCookie withExpiresAfter(TimeUnit aTimeUnit, long aTime)
      Builder method for the method setExpiresAfter(TimeUnit, long).
      Parameters:
      aTimeUnit - The TimeUnit of the provided time
      aTime - The provided time after which to expire
      Returns:
      This cookie instance for further configuration.
    • withVersion

      public ResponseCookie withVersion(String aVersion)
      Builder method for setVersion(String).
      Parameters:
      aVersion - Sets the version.
      Returns:
      This instance as of the Builder-Pattern.
    • withMaxAge

      public ResponseCookie withMaxAge(int aMaxAge)
      Builder method for setMaxAge(int).
      Parameters:
      aMaxAge - Sets the Max-Age.
      Returns:
      This instance as of the Builder-Pattern.
    • withSecure

      public ResponseCookie withSecure(boolean isSecure)
      Sets whether it be a secure HTTP cookie. Such a cookie only be transferred via HTTPS. Returns this instance as of the Builder-Pattern.
      Parameters:
      isSecure - True in case of being a secure only cookie.
      Returns:
      Returns this instance as of the Builder-Pattern.
    • withHttpCookie

      public ResponseCookie withHttpCookie(String aCookie)
      Sets the cookie according to the provided HTTP cookie text via Cookie.fromHttpCookie(String).
      Specified by:
      withHttpCookie in interface Cookie
      Parameters:
      aCookie - The HTTP cookie text.
      Returns:
      A Cookie instance as of the Builder-Pattern.
    • fromHttpCookie

      public void fromHttpCookie(String aHttpCookie)
      Sets the cookie according to the provided HTTP cookie text.
      Specified by:
      fromHttpCookie in interface Cookie
      Parameters:
      aHttpCookie - The HTTP cookie text.
    • toHttpCookie

      public String toHttpCookie()
      Returns the cookie to be assigned to a cookie Header-Field.
      Specified by:
      toHttpCookie in interface Cookie
      Returns:
      The cookie value for a Header-Field.
    • toString

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