Class HttpCookie
java.lang.Object
eu.cloudnetservice.driver.network.http.HttpCookie
- All Implemented Interfaces:
eu.cloudnetservice.common.Nameable
Represents a cookie which can be sent by a client to the server using the
Cookie header, and vise-vera using
the Set-Cookie header. See the mdn
documentation about cookies for more details.- Since:
- 4.0
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionHttpCookie(@NonNull String name, @NonNull String value) Constructs a new http cookie instance.HttpCookie(@NonNull String name, @NonNull String value, @Nullable String domain, @Nullable String path, boolean httpOnly, boolean secure, boolean wrap, long maxAge) Constructs a new http cookie instance.HttpCookie(@NonNull String name, @NonNull String value, @Nullable String domain, @Nullable String path, long maxAge) Constructs a new http cookie instance. -
Method Summary
Modifier and TypeMethodDescriptiondomain()Get the domain which is allowed to receive the cookie.booleanhttpOnly()Get if the cookie is only visible to http request, blocking access to the cookie from e.g.longmaxAge()Get the max age this cookie persists on the client side until it gets emitted.name()Get the name of this cookie.path()Get the path which must be present in the request uri to send the cookie to the server.booleansecure()Get if this cookie should only get transferred to the server if the server connection is encrypted (using https).value()Get the value of this cookie.booleanwrap()Get if the value of this cookie is wrapped in double quotes.
-
Field Details
-
name
-
value
-
domain
-
path
-
httpOnly
protected final boolean httpOnly -
secure
protected final boolean secure -
wrap
protected final boolean wrap -
maxAge
protected final long maxAge
-
-
Constructor Details
-
HttpCookie
Constructs a new http cookie instance. This constructor only takes the required values of a cookie.- Parameters:
name- the name of the cookie.value- the value of the cookie.- Throws:
NullPointerException- if either the given name or value is null.
-
HttpCookie
public HttpCookie(@NonNull @NonNull String name, @NonNull @NonNull String value, @Nullable @Nullable String domain, @Nullable @Nullable String path, long maxAge) Constructs a new http cookie instance.- Parameters:
name- the name of the cookie.value- the value of the cookie.domain- the domain which is allowed to access the cookie. If not set it defaults to the current domain, excluding subdomains.path- the path that must request in the request uri in order to include this cookie in the header.maxAge- the maximum age until the cookie gets deleted from the client.- Throws:
NullPointerException- if either the given name or value is null.
-
HttpCookie
public HttpCookie(@NonNull @NonNull String name, @NonNull @NonNull String value, @Nullable @Nullable String domain, @Nullable @Nullable String path, boolean httpOnly, boolean secure, boolean wrap, long maxAge) Constructs a new http cookie instance.- Parameters:
name- the name of the cookie.value- the value of the cookie.domain- the domain which is allowed to access the cookie. If not set it defaults to the current domain, excluding subdomains.path- the path that must request in the request uri in order to include this cookie in the header.httpOnly- sets that the cookie is invisible to scripts and will only be sent in http requests to the server.secure- sets that the cookie is only sent to the server when the connection is encrypted (using https).wrap- sets if the value of this cookie should be wrapped in double quotes.maxAge- the maximum age until the cookie gets deleted from the client.- Throws:
NullPointerException- if either the given name or value is null.
-
-
Method Details
-
name
Get the name of this cookie.- Specified by:
namein interfaceeu.cloudnetservice.common.Nameable- Returns:
- the name of this cookie.
-
value
Get the value of this cookie.- Returns:
- the value of this cookie.
-
domain
Get the domain which is allowed to receive the cookie. If not set only the current domain is allowed to receive the cookie, excluding subdomains. If set to the current domain then subdomains are always included.- Returns:
- the domain which is allowed to receive the cookie.
-
path
Get the path which must be present in the request uri to send the cookie to the server. For example, if the path is set to/docsthen the following uris would receive the cookie:- /docs
- /docs/
- /docs/getting-started
- /
- /helpdesk
- /documentation/getting-started
- Returns:
- the path which must be present in the request uri to send the cookie to the server.
-
maxAge
public long maxAge()Get the max age this cookie persists on the client side until it gets emitted.- Returns:
- the max age of this cookie.
-
httpOnly
public boolean httpOnly()Get if the cookie is only visible to http request, blocking access to the cookie from e.g. scripts running in the browser.- Returns:
- if the cookie is only visible to http request.
-
secure
public boolean secure()Get if this cookie should only get transferred to the server if the server connection is encrypted (using https). The only point when it is transmitted to the server even when using http is to localhost.- Returns:
- if this cookie should only get transferred to the server if the server connection is encrypted.
-
wrap
public boolean wrap()Get if the value of this cookie is wrapped in double quotes. This is an en-/de- coder only option which is not visible on the client side.- Returns:
- if the value of this cookie is wrapped in double quotes
-