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:
-
Nested Class Summary
Nested classes/interfaces inherited from class PropertyImpl
PropertyImpl.PropertyBuilderImplNested classes/interfaces inherited from class RelationImpl
RelationImpl.RelationBuilderImpl<K,V> Nested classes/interfaces inherited from interface DomainAccessor
DomainAccessor.DomainBuilder<B>, DomainAccessor.DomainMutator, DomainAccessor.DomainPropertyNested classes/interfaces inherited from interface KeyAccessor
KeyAccessor.KeyBuilder<K,B>, KeyAccessor.KeyMutator<K>, KeyAccessor.KeyProperty<K> Nested classes/interfaces inherited from interface PathAccessor
PathAccessor.PathBuilder<T,B>, PathAccessor.PathMutator<T>, PathAccessor.PathProperty<T> Nested classes/interfaces inherited from interface Property
Property.PropertyBuilderNested classes/interfaces inherited from interface Relation
Relation.RelationBuilder<K,V> Nested classes/interfaces inherited from interface ValueAccessor
ValueAccessor.ValueBuilder<V,B>, ValueAccessor.ValueMutator<V>, ValueAccessor.ValueProperty<V> -
Field Summary
Fields inherited from class RelationImpl
_key, _value -
Constructor Summary
ConstructorsConstructorDescriptionInstantiates a new response cookie impl.ResponseCookie(String aHttpCookie) Constructs aResponseCookiefrom the given HTTP cookie.ResponseCookie(String aCookieName, String aValue) Instantiates the classResponseCookie.ResponseCookie(String aCookieName, String aValue, int aMaxAge, String aDomain, String aPath, boolean isSecure, boolean isHttpOnly, String aVersion) Instantiates the classResponseCookie.ResponseCookie(String aCookieName, String aValue, Date aExpiresDate, String aDomain, String aPath, boolean isSecure, boolean isHttpOnly, String aVersion) Instantiates the classResponseCookie.ResponseCookie(Cookie aCookie) Instantiates the classResponseCookie. -
Method Summary
Modifier and TypeMethodDescriptionvoidfromHttpCookie(String aHttpCookie) Sets the cookie according to the provided HTTP cookie text.Returns the expiration date of this cookie.intReturns the Max-Age (seconds) for this cookie.getPath()Returns the version this cookie.booleanReturns true if we have an HTTP only cookie.booleanisSecure()Returns true if we have a secure HTTP cookie.voidvoidsetExpiresAfter(TimeUnit aTimeUnit, long aTime) Sets the expires date to the current time plus the provided time.voidsetExpiresDate(Date aExpireDate) Sets the expiration date of this cookie.voidsetHttpOnly(boolean isHttpOnly) Sets whether it be an HTTP only cookie.voidsetMaxAge(int aMaxAge) Sets the Max-Age (seconds) of this cookie.voidvoidsetSecure(boolean isSecure) Sets whether it be a secure HTTP cookie.voidsetVersion(String aVersion) Sets the version of this cookie.Returns the cookie to be assigned to a cookie Header-Field.toString()withDomain(String aDomain) Sets the domain for this cookie.withExpiresAfter(TimeUnit aTimeUnit, long aTime) Builder method for the methodsetExpiresAfter(TimeUnit, long).withExpiresDate(Date aExpiresDate) Sets the expiration date of this cookie and returns this instance as of the Builder-Pattern.withHttpCookie(String aCookie) Sets the cookie according to the provided HTTP cookie text viaCookie.fromHttpCookie(String).withHttpOnly(boolean isHttpOnly) Sets whether it be an HTTP only cookie.withMaxAge(int aMaxAge) Builder method forsetMaxAge(int).Sets the path of the cookie.withSecure(boolean isSecure) Sets whether it be a secure HTTP cookie.withVersion(String aVersion) Builder method forsetVersion(String).Methods inherited from class PropertyImpl.PropertyBuilderImpl
setKey, setValueMethods inherited from class RelationImpl
getKey, getValueMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface DomainAccessor.DomainProperty
letDomainMethods inherited from interface KeyAccessor
getKeyMethods inherited from interface KeyAccessor.KeyMutator
setKeyMethods inherited from interface KeyAccessor.KeyProperty
letKeyMethods inherited from interface PathAccessor.PathProperty
letPathMethods inherited from interface Property
toPropertyMethods inherited from interface Property.PropertyBuilder
withKey, withValueMethods inherited from interface ValueAccessor
getValue, getValueOr, hasValueMethods inherited from interface ValueAccessor.ValueMutator
setValueMethods inherited from interface ValueAccessor.ValueProperty
letValue
-
Constructor Details
-
ResponseCookie
public ResponseCookie()Instantiates a new response cookie impl. -
ResponseCookie
Instantiates the classResponseCookie.- See Also:
-
ResponseCookie
Constructs aResponseCookiefrom the given HTTP cookie.- Parameters:
aHttpCookie- The text as being found in the according HTTP header field.
-
ResponseCookie
Instantiates the classResponseCookie.- Parameters:
aCookie- TheCookiefrom 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 classResponseCookie.- Parameters:
aExpiresDate- 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.- See Also:
-
ResponseCookie
public ResponseCookie(String aCookieName, String aValue, int aMaxAge, String aDomain, String aPath, boolean isSecure, boolean isHttpOnly, String aVersion) Instantiates the classResponseCookie.- Parameters:
aMaxAge- 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.- 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
-
setVersion
Sets the version of this cookie.- Parameters:
aVersion- Sets the version.
-
getPath
- Specified by:
getPathin interfacePathAccessor<String>
-
setPath
- Specified by:
setPathin interfacePathAccessor.PathMutator<String>
-
getExpiresDate
Returns the expiration date of this cookie.- Returns:
- The expiration date.
-
setExpiresDate
Sets the expiration date of this cookie.- Parameters:
aExpireDate- The expiration date.
-
getDomain
- Specified by:
getDomainin interfaceDomainAccessor
-
setDomain
- Specified by:
setDomainin interfaceDomainAccessor.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
Sets the expires date to the current time plus the provided time. UsegetExpiresDate()to retrieve the resulting effectiveDate.- Parameters:
aTimeUnit- TheTimeUnitof the provided timeaTime- The provided time after which to expire
-
withExpiresDate
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
Sets the path of the cookie.- Specified by:
withPathin interfacePathAccessor.PathBuilder<String, ResponseCookie>
-
withDomain
Sets the domain for this cookie.- Specified by:
withDomainin interfaceDomainAccessor.DomainBuilder<ResponseCookie>
-
withHttpOnly
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
Builder method for the methodsetExpiresAfter(TimeUnit, long).- Parameters:
aTimeUnit- TheTimeUnitof the provided timeaTime- The provided time after which to expire- Returns:
- This cookie instance for further configuration.
-
withVersion
Builder method forsetVersion(String).- Parameters:
aVersion- Sets the version.- Returns:
- This instance as of the Builder-Pattern.
-
withMaxAge
Builder method forsetMaxAge(int).- Parameters:
aMaxAge- Sets the Max-Age.- Returns:
- This instance as of the Builder-Pattern.
-
withSecure
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
Sets the cookie according to the provided HTTP cookie text viaCookie.fromHttpCookie(String).- Specified by:
withHttpCookiein interfaceCookie- Parameters:
aCookie- The HTTP cookie text.- Returns:
- A
Cookieinstance as of the Builder-Pattern.
-
fromHttpCookie
Sets the cookie according to the provided HTTP cookie text.- Specified by:
fromHttpCookiein interfaceCookie- Parameters:
aHttpCookie- The HTTP cookie text.
-
toHttpCookie
Returns the cookie to be assigned to a cookie Header-Field.- Specified by:
toHttpCookiein interfaceCookie- Returns:
- The cookie value for a Header-Field.
-
toString
- Overrides:
toStringin classPropertyImpl.PropertyBuilderImpl
-