public class HTTPCookieHandler
extends java.lang.Object
HTTPClient.getCookieHandler()
Modifier and Type | Field and Description |
---|---|
static java.util.Comparator<java.net.HttpCookie> |
domainPathNameComparator
Used to sort a list of cookies first by domain, second by path and third by name (all case insensitive).
|
Modifier and Type | Method and Description |
---|---|
boolean |
addOrReplaceCookie(java.net.HttpCookie httpCookie)
Add or replace a cookie.
|
static boolean |
domainMatches(java.lang.String domain,
java.lang.String host)
Replacement for java.net.HttpCookie.domainMatches(..) because the java original implementation does not support RFC 6265 section 4.1.2.3
|
void |
dumpToStdout()
For debug purpose only, dump all cookies to stdout.
|
java.util.ArrayList<java.net.HttpCookie> |
getAllCookies()
Get all cookies.
|
java.util.ArrayList<java.net.HttpCookie> |
getAllPermanentCookies()
Get all permanent cookies (all cookies which are not session cookies).
|
java.net.HttpCookie |
getCookie(java.lang.String cookieName,
java.lang.String domain,
java.lang.String path)
Get a cookie selected by name, domain and path.
|
java.net.HttpCookie |
getCookieByName(java.lang.String cookieName)
Get the first matching cookie selected by name.
|
java.util.ArrayList<java.net.HttpCookie> |
getCookiesByName(java.lang.String cookieName)
Get all cookies which match to a specific cookie name.
|
boolean |
isThirdPartyCookiesEnabled()
Get if third party cookies are enabled.
|
static void |
main(java.lang.String[] args)
Internal test program.
|
void |
removeAllCookies()
Remove all cookies.
|
int |
removeAllExpiredCookies()
Remove all expired cookies.
|
int |
removeAllSessionCookies()
Remove all session cookies.
|
boolean |
removeCookie(java.net.HttpCookie httpCookie)
Remove a cookie.
|
int |
removeCookiesByName(java.lang.String cookieName)
Remove all cookies which match to a specific cookie name.
|
void |
setThirdPartyCookiesEnabled(boolean thirdPartyCookiesEnabled)
Enable or disable third party cookies.
|
public static java.util.Comparator<java.net.HttpCookie> domainPathNameComparator
public boolean isThirdPartyCookiesEnabled()
public void setThirdPartyCookiesEnabled(boolean thirdPartyCookiesEnabled)
thirdPartyCookiesEnabled
- true = enable third party cookies, false = disable third party cookiespublic boolean addOrReplaceCookie(java.net.HttpCookie httpCookie) throws java.lang.IllegalArgumentException
httpCookie
- the cookie to add or to replacejava.lang.IllegalArgumentException
- if the cookie has no domain or path attribute, or if the cookie is already expiredpublic boolean removeCookie(java.net.HttpCookie httpCookie)
httpCookie
- the cookie to removepublic int removeCookiesByName(java.lang.String cookieName)
cookieName
- the name of the cookie(s)public int removeAllExpiredCookies()
public int removeAllSessionCookies()
public void removeAllCookies()
public java.util.ArrayList<java.net.HttpCookie> getAllCookies()
public java.util.ArrayList<java.net.HttpCookie> getAllPermanentCookies()
public java.util.ArrayList<java.net.HttpCookie> getCookiesByName(java.lang.String cookieName)
cookieName
- the name of the cookie(s)public java.net.HttpCookie getCookieByName(java.lang.String cookieName)
cookieName
- the name of the cookiepublic java.net.HttpCookie getCookie(java.lang.String cookieName, java.lang.String domain, java.lang.String path)
cookieName
- the name of the cookiedomain
- the domain of the cookiepath
- the path of the cookiepublic void dumpToStdout()
public static boolean domainMatches(java.lang.String domain, java.lang.String host)
domain
- the cookie domainhost
- the host of the HTTP URLpublic static void main(java.lang.String[] args)
args
- [no args]