use of java.net.HttpCookie in project xUtils3 by wyouflf.
the class CookieEntity method toHttpCookie.
public HttpCookie toHttpCookie() {
HttpCookie cookie = new HttpCookie(name, value);
cookie.setComment(comment);
cookie.setCommentURL(commentURL);
cookie.setDiscard(discard);
cookie.setDomain(domain);
if (expiry == -1L) {
cookie.setMaxAge(-1L);
} else {
cookie.setMaxAge((expiry - System.currentTimeMillis()) / 1000L);
}
cookie.setPath(path);
cookie.setPortlist(portList);
cookie.setSecure(secure);
cookie.setVersion(version);
return cookie;
}
use of java.net.HttpCookie in project zaproxy by zaproxy.
the class HttpRequestHeader method setCookies.
/**
* Construct new "Cookie:" line in request header based on HttpCookies.
*
* @param cookies the new cookies
*/
public void setCookies(List<HttpCookie> cookies) {
if (cookies.isEmpty()) {
setHeader(HttpHeader.COOKIE, null);
}
StringBuilder sbData = new StringBuilder();
for (HttpCookie c : cookies) {
sbData.append(c.getName());
sbData.append('=');
sbData.append(c.getValue());
sbData.append("; ");
}
if (sbData.length() <= 3) {
setHeader(HttpHeader.COOKIE, null);
return;
}
final String data = sbData.substring(0, sbData.length() - 2);
setHeader(HttpHeader.COOKIE, data);
}
use of java.net.HttpCookie in project jdk8u_jdk by JetBrains.
the class NullUriCookieTest method checkCookieNullUri.
static void checkCookieNullUri() throws Exception {
//get a cookie store implementation and add a cookie to the store with null URI
CookieStore cookieStore = (new CookieManager()).getCookieStore();
//Check if removeAll() retrurns false on an empty CookieStore
if (cookieStore.removeAll()) {
fail = true;
}
checkFail("removeAll on empty store should return false");
HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
cookie.setDomain("foo.com");
cookieStore.add(null, cookie);
//Retrieve added cookie
URI uri = new URI("http://foo.com");
List<HttpCookie> addedCookieList = cookieStore.get(uri);
//Verify CookieStore behaves well
if (addedCookieList.size() != 1) {
fail = true;
}
checkFail("Abnormal size of cookie jar");
for (HttpCookie chip : addedCookieList) {
if (!chip.equals(cookie)) {
fail = true;
}
}
checkFail("Cookie not retrieved from Cookie Jar");
boolean ret = cookieStore.remove(null, cookie);
if (!ret) {
fail = true;
}
checkFail("Abnormal removal behaviour from Cookie Jar");
}
use of java.net.HttpCookie in project jdk8u_jdk by JetBrains.
the class TestHttpCookie method misc.
static void misc() {
header("Test equals()");
// test equals()
HttpCookie c1 = new HttpCookie("Customer", "WILE_E_COYOTE");
c1.setDomain(".coyote.org");
c1.setPath("/acme");
HttpCookie c2 = (HttpCookie) c1.clone();
eq(c1, c2, true);
// test equals() when domain and path are null
c1 = new HttpCookie("Customer", "WILE_E_COYOTE");
c2 = new HttpCookie("CUSTOMER", "WILE_E_COYOTE");
eq(c1, c2, true);
// path is case-sensitive
c1 = new HttpCookie("Customer", "WILE_E_COYOTE");
c2 = new HttpCookie("CUSTOMER", "WILE_E_COYOTE");
c1.setPath("/acme");
c2.setPath("/ACME");
eq(c1, c2, false);
header("Test domainMatches()");
dm(".foo.com", "y.x.foo.com", false);
dm(".foo.com", "x.foo.com", true);
dm(".com", "whatever.com", false);
dm(".com.", "whatever.com", false);
dm(".ajax.com", "ajax.com", true);
dm(".local", "example.local", true);
dm("example.local", "example", true);
// bug 6277808
testCount++;
try {
c1 = new HttpCookie("", "whatever");
} catch (IllegalArgumentException ignored) {
// expected exception; no-op
}
// CR 6692802: HttpOnly flag
test("set-cookie: CUSTOMER=WILE_E_COYOTE;HttpOnly").httpOnly(true);
test("set-cookie: CUSTOMER=WILE_E_COYOTE").httpOnly(false);
// space disallowed in name (both Netscape and RFC2965)
test("set-cookie: CUST OMER=WILE_E_COYOTE").nil();
}
use of java.net.HttpCookie in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.
the class PersistentCookieStore method loadAllFromPersistence.
private void loadAllFromPersistence() {
allCookies = new HashMap<URI, Set<HttpCookie>>();
Map<String, ?> allPairs = sharedPreferences.getAll();
for (Map.Entry<String, ?> entry : allPairs.entrySet()) {
String[] uriAndName = entry.getKey().split(SP_KEY_DELIMITER_REGEX, 2);
try {
URI uri = new URI(uriAndName[0]);
String encodedCookie = (String) entry.getValue();
HttpCookie cookie = new SerializableHttpCookie().decode(encodedCookie);
Set<HttpCookie> targetCookies = allCookies.get(uri);
if (targetCookies == null) {
targetCookies = new HashSet<HttpCookie>();
allCookies.put(uri, targetCookies);
}
// Repeated cookies cannot exist in persistence
// targetCookies.remove(cookie)
targetCookies.add(cookie);
} catch (URISyntaxException e) {
Log.w(TAG, e);
}
}
}
Aggregations