Package kong.unirest.core
Class Cookie
- java.lang.Object
-
- kong.unirest.core.Cookie
-
public class Cookie extends java.lang.Object
Represents a cookie parsed from the set-cookie header per https://tools.ietf.org/html/rfc6265 note that the RFC is awful. The wikipedia article is far easier to understand https://en.wikipedia.org/wiki/HTTP_cookie
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Cookie.Pair
static class
Cookie.SameSite
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
domain
private java.time.ZonedDateTime
expires
private boolean
httpOnly
private java.lang.Integer
maxAge
private java.lang.String
name
private java.lang.String
path
private Cookie.SameSite
sameSite
private boolean
secure
private java.lang.String
value
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.String
getDecode(java.lang.String sub)
java.lang.String
getDomain()
java.time.ZonedDateTime
getExpiration()
Per Wikipedia: The Expires attribute defines a specific date and time for when the browser should delete the cookie.int
getMaxAge()
Per Wikipedia: the Max-Age attribute can be used to set the cookie's expiration as an interval of seconds in the future, relative to the time the browser received the cookie.java.lang.String
getName()
java.lang.String
getPath()
Cookie.SameSite
getSameSite()
returns the SameSite attributejava.lang.String
getUrlDecodedValue()
java.lang.String
getValue()
boolean
isHttpOnly()
Per Wikipedia: The HttpOnly attribute directs browsers not to expose cookies through channels other than HTTP (and HTTPS) requests.boolean
isSecure()
Per Wikipedia: The Secure attribute is meant to keep cookie communication limited to encrypted transmission, directing browsers to use cookies only via secure/encrypted connections.private void
parseExpires(java.lang.String text)
private void
parseSection(java.lang.String[] sub)
void
setDomain(java.lang.String domain)
void
setHttpOnly(boolean httpOnly)
void
setPath(java.lang.String path)
private java.lang.String
stripQuoteWrapper(java.lang.String sub)
java.lang.String
toString()
-
-
-
Field Detail
-
name
private java.lang.String name
-
value
private java.lang.String value
-
domain
private java.lang.String domain
-
path
private java.lang.String path
-
httpOnly
private boolean httpOnly
-
maxAge
private java.lang.Integer maxAge
-
expires
private java.time.ZonedDateTime expires
-
secure
private boolean secure
-
sameSite
private Cookie.SameSite sameSite
-
-
Method Detail
-
getDecode
private java.lang.String getDecode(java.lang.String sub)
-
stripQuoteWrapper
private java.lang.String stripQuoteWrapper(java.lang.String sub)
-
parseSection
private void parseSection(java.lang.String[] sub)
-
parseExpires
private void parseExpires(java.lang.String text)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
setDomain
public void setDomain(java.lang.String domain)
-
setPath
public void setPath(java.lang.String path)
-
setHttpOnly
public void setHttpOnly(boolean httpOnly)
-
getName
public java.lang.String getName()
- Returns:
- the cookie-name
-
getValue
public java.lang.String getValue()
- Returns:
- the cookie-value
-
getUrlDecodedValue
public java.lang.String getUrlDecodedValue()
- Returns:
- the cookie-value, url-decoded
-
getDomain
public java.lang.String getDomain()
- Returns:
- the domain value of the cookie
-
getPath
public java.lang.String getPath()
- Returns:
- the path value of the cookie
-
isHttpOnly
public boolean isHttpOnly()
Per Wikipedia: The HttpOnly attribute directs browsers not to expose cookies through channels other than HTTP (and HTTPS) requests. This means that the cookie cannot be accessed via client-side scripting languages (notably JavaScript), and therefore cannot be stolen easily via cross-site scripting (a pervasive attack technique)- Returns:
- a boolean if the cookie is httpOnly
-
isSecure
public boolean isSecure()
Per Wikipedia: The Secure attribute is meant to keep cookie communication limited to encrypted transmission, directing browsers to use cookies only via secure/encrypted connections.- Returns:
- a boolean of if the cookie is secure
-
getMaxAge
public int getMaxAge()
Per Wikipedia: the Max-Age attribute can be used to set the cookie's expiration as an interval of seconds in the future, relative to the time the browser received the cookie.- Returns:
- Max-Age attribute
-
getExpiration
public java.time.ZonedDateTime getExpiration()
Per Wikipedia: The Expires attribute defines a specific date and time for when the browser should delete the cookie.- Returns:
- a ZonedDateTime of the expiration
-
getSameSite
public Cookie.SameSite getSameSite()
returns the SameSite attribute- Returns:
- the SameSite attribute if set. or null
-
-