Package org.refcodes.net
Class ResponseCookieImpl
- java.lang.Object
-
- org.refcodes.structure.RelationImpl<java.lang.String,java.lang.String>
-
- org.refcodes.structure.PropertyImpl
-
- org.refcodes.structure.PropertyImpl.PropertyBuilderImpl
-
- org.refcodes.net.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<java.lang.String>
,org.refcodes.mixin.KeyAccessor.KeyBuilder<java.lang.String,org.refcodes.structure.Relation.RelationBuilder<java.lang.String,java.lang.String>>
,org.refcodes.mixin.KeyAccessor.KeyMutator<java.lang.String>
,org.refcodes.mixin.KeyAccessor.KeyProperty<java.lang.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<java.lang.String>
,org.refcodes.mixin.ValueAccessor.ValueBuilder<java.lang.String,org.refcodes.structure.Relation.RelationBuilder<java.lang.String,java.lang.String>>
,org.refcodes.mixin.ValueAccessor.ValueMutator<java.lang.String>
,org.refcodes.mixin.ValueAccessor.ValueProperty<java.lang.String>
,Cookie
,ResponseCookie
,org.refcodes.structure.Property
,org.refcodes.structure.Property.PropertyBuilder
,org.refcodes.structure.Relation<java.lang.String,java.lang.String>
,org.refcodes.structure.Relation.RelationBuilder<java.lang.String,java.lang.String>
public class ResponseCookieImpl extends org.refcodes.structure.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 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 java.lang.Object,B extends org.refcodes.mixin.KeyAccessor.KeyBuilder<K,B>>, org.refcodes.mixin.KeyAccessor.KeyMutator<K extends java.lang.Object>, org.refcodes.mixin.KeyAccessor.KeyProperty<K extends java.lang.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.structure.Property
org.refcodes.structure.Property.PropertyBuilder
-
Nested classes/interfaces inherited from class org.refcodes.structure.PropertyImpl
org.refcodes.structure.PropertyImpl.PropertyBuilderImpl
-
Nested classes/interfaces inherited from interface org.refcodes.structure.Relation
org.refcodes.structure.Relation.RelationBuilder<K extends java.lang.Object,V extends java.lang.Object>
-
Nested classes/interfaces inherited from class org.refcodes.structure.RelationImpl
org.refcodes.structure.RelationImpl.RelationBuilderImpl<K extends java.lang.Object,V extends java.lang.Object>
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.ValueAccessor
org.refcodes.mixin.ValueAccessor.ValueBuilder<V extends java.lang.Object,B extends org.refcodes.mixin.ValueAccessor.ValueBuilder<V,B>>, org.refcodes.mixin.ValueAccessor.ValueMutator<V extends java.lang.Object>, org.refcodes.mixin.ValueAccessor.ValueProperty<V extends java.lang.Object>
-
-
Constructor Summary
Constructors Constructor Description ResponseCookieImpl()
Instantiates a new response cookie impl.ResponseCookieImpl(java.lang.String aHttpCookie)
Constructs aResponseCookie
from the given HTTP cookie.ResponseCookieImpl(java.lang.String aCookieName, java.lang.String aValue)
Constructs aResponseCookie
.ResponseCookieImpl(java.lang.String aCookieName, java.lang.String aValue, int aMaxAge, java.lang.String aDomain, java.lang.String aPath, boolean isSecure, boolean isHttpOnly, java.lang.String aVersion)
Constructs aResponseCookie
.ResponseCookieImpl(java.lang.String aCookieName, java.lang.String aValue, java.util.Date aExpiresDate, java.lang.String aDomain, java.lang.String aPath, boolean isSecure, boolean isHttpOnly, java.lang.String aVersion)
Constructs aResponseCookie
.ResponseCookieImpl(Cookie aCookie)
Constructs aResponseCookie
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getDomain()
java.util.Date
getExpiresDate()
Returns the expiration date of this cookie.int
getMaxAge()
Returns the Max-Age (seconds) for this cookie.java.lang.String
getPath()
java.lang.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(java.lang.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(java.util.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(java.lang.String aPath)
void
setSecure(boolean isSecure)
Sets whether it be a secure HTTP cookie.void
setVersion(java.lang.String aVersion)
Sets the version of this cookie.java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from class org.refcodes.structure.PropertyImpl.PropertyBuilderImpl
setKey, setValue
-
Methods inherited from interface org.refcodes.net.ResponseCookie
fromHttpCookie, toHttpCookie, withDomain, withExpiresAfter, withExpiresDate, withHttpCookie, withHttpOnly, withMaxAge, withPath, withSecure, withVersion
-
-
-
-
Constructor Detail
-
ResponseCookieImpl
public ResponseCookieImpl()
Instantiates a new response cookie impl.
-
ResponseCookieImpl
public ResponseCookieImpl(java.lang.String aCookieName, java.lang.String aValue)
Constructs aResponseCookie
.- Parameters:
aCookieName
- The name of the cookie.aValue
- The value for the cookie.
-
ResponseCookieImpl
public ResponseCookieImpl(java.lang.String aHttpCookie)
Constructs aResponseCookie
from the given HTTP cookie.- Parameters:
aHttpCookie
- The text as being found in the according HTTP header field.
-
ResponseCookieImpl
public ResponseCookieImpl(Cookie aCookie)
Constructs aResponseCookie
.- Parameters:
aCookie
- TheCookie
from which to take the data.
-
ResponseCookieImpl
public ResponseCookieImpl(java.lang.String aCookieName, java.lang.String aValue, java.util.Date aExpiresDate, java.lang.String aDomain, java.lang.String aPath, boolean isSecure, boolean isHttpOnly, java.lang.String aVersion)
Constructs aResponseCookie
.- Parameters:
aCookieName
- The name for the cookieaValue
- The value of the cookieaExpiresDate
- The expiration date of the cookieaDomain
- The domain of the cookieaPath
- The path of the cookieisSecure
- The secure flag of the cookieisHttpOnly
- The HTTP-only flag of the cookieaVersion
- The version of the cookie.
-
ResponseCookieImpl
public ResponseCookieImpl(java.lang.String aCookieName, java.lang.String aValue, int aMaxAge, java.lang.String aDomain, java.lang.String aPath, boolean isSecure, boolean isHttpOnly, java.lang.String aVersion)
Constructs aResponseCookie
.- Parameters:
aCookieName
- The name for the cookieaValue
- The value of the cookieaMaxAge
- Sets the Max-Age (seconds) of this cookie.aDomain
- The domain of the cookieaPath
- The path of the cookieisSecure
- The secure flag of the cookieisHttpOnly
- The HTTP-only flag of the cookieaVersion
- The version of the cookie.
-
-
Method Detail
-
getMaxAge
public int getMaxAge()
Returns the Max-Age (seconds) for this cookie.- Specified by:
getMaxAge
in interfaceResponseCookie
- Returns:
- The Max-Age.
-
setMaxAge
public void setMaxAge(int aMaxAge)
Sets the Max-Age (seconds) of this cookie.- Specified by:
setMaxAge
in interfaceResponseCookie
- Parameters:
aMaxAge
- Sets the Max-Age.
-
getVersion
public java.lang.String getVersion()
Returns the version this cookie.- Specified by:
getVersion
in interfaceResponseCookie
- Returns:
- The version.
-
setVersion
public void setVersion(java.lang.String aVersion)
Sets the version of this cookie.- Specified by:
setVersion
in interfaceResponseCookie
- Parameters:
aVersion
- Sets the version.
-
getPath
public java.lang.String getPath()
- Specified by:
getPath
in interfaceorg.refcodes.mixin.PathAccessor
-
setPath
public void setPath(java.lang.String aPath)
- Specified by:
setPath
in interfaceorg.refcodes.mixin.PathAccessor.PathMutator
-
getExpiresDate
public java.util.Date getExpiresDate()
Returns the expiration date of this cookie.- Specified by:
getExpiresDate
in interfaceResponseCookie
- Returns:
- The expiration date.
-
setExpiresDate
public void setExpiresDate(java.util.Date aExpireDate)
Sets the expiration date of this cookie.- Specified by:
setExpiresDate
in interfaceResponseCookie
- Parameters:
aExpireDate
- The expiration date.
-
getDomain
public java.lang.String getDomain()
- Specified by:
getDomain
in interfaceorg.refcodes.mixin.DomainAccessor
-
setDomain
public void setDomain(java.lang.String aDomain)
- Specified by:
setDomain
in interfaceorg.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 interfaceResponseCookie
- 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 interfaceResponseCookie
- 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 interfaceResponseCookie
- 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 interfaceResponseCookie
- 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. UseResponseCookie.getExpiresDate()
to retrieve the resulting effectiveDate
.- Specified by:
setExpiresAfter
in interfaceResponseCookie
- Parameters:
aTimeUnit
- TheTimeUnit
of the provided timeaTime
- The provided time after which to expire
-
toString
public java.lang.String toString()
- Overrides:
toString
in classorg.refcodes.structure.PropertyImpl.PropertyBuilderImpl
-
-