use of com.firenio.codec.http11.Cookie in project EhViewer by seven332.
the class CookieRepositoryTest method testRemoveByExpired.
@Test
public void testRemoveByExpired() {
Context app = RuntimeEnvironment.application;
HttpUrl urlEh = HttpUrl.parse("http://www.ehviewer.com/");
Cookie cookieEh1 = new Cookie.Builder().name("level").value("999").domain("www.ehviewer.com").path("/").expiresAt(System.currentTimeMillis() + 100000).build();
Cookie cookieEh2 = new Cookie.Builder().name("level").value("0").domain("www.ehviewer.com").path("/").expiresAt(System.currentTimeMillis() - 100000).build();
CookieRepository repository = new CookieRepository(app, "cookie.db");
repository.saveFromResponse(urlEh, Collections.singletonList(cookieEh1));
repository.saveFromResponse(urlEh, Collections.singletonList(cookieEh2));
Map<String, CookieSet> map = Reflect.on(repository).field("map").get();
assertEquals(1, map.size());
equals(map.get("www.ehviewer.com"), Collections.<Cookie>emptyList());
repository.close();
repository = new CookieRepository(app, "cookie.db");
map = Reflect.on(repository).field("map").get();
assertEquals(0, map.size());
repository.close();
}
use of com.firenio.codec.http11.Cookie in project EhViewer by seven332.
the class CookieRepositoryTest method equals.
private void equals(CookieSet cookieSet, List<Cookie> cookies) {
assertNotNull(cookieSet);
assertNotNull(cookies);
Map<CookieSet.Key, Cookie> map = Reflect.on(cookieSet).field("map").get();
assertEquals(cookies.size(), map.size());
for (Cookie cookie : cookies) {
assertEquals(cookie, map.get(new CookieSet.Key(cookie)));
}
}
use of com.firenio.codec.http11.Cookie in project EhViewer by seven332.
the class CookieRepositoryTest method testRemoveByNonPersistent.
@Test
public void testRemoveByNonPersistent() {
Context app = RuntimeEnvironment.application;
HttpUrl urlEh = HttpUrl.parse("http://www.ehviewer.com/");
Cookie cookieEh1 = new Cookie.Builder().name("level").value("999").domain("www.ehviewer.com").path("/").expiresAt(System.currentTimeMillis() + 100000).build();
Cookie cookieEh2 = new Cookie.Builder().name("level").value("0").domain("www.ehviewer.com").path("/").build();
CookieRepository repository = new CookieRepository(app, "cookie.db");
repository.saveFromResponse(urlEh, Collections.singletonList(cookieEh1));
repository.saveFromResponse(urlEh, Collections.singletonList(cookieEh2));
Map<String, CookieSet> map = Reflect.on(repository).field("map").get();
assertEquals(1, map.size());
equals(map.get("www.ehviewer.com"), Collections.singletonList(cookieEh2));
repository.close();
repository = new CookieRepository(app, "cookie.db");
map = Reflect.on(repository).field("map").get();
assertEquals(0, map.size());
repository.close();
}
use of com.firenio.codec.http11.Cookie in project EhViewer by seven332.
the class IdentityCookiePreference method init.
private void init() {
EhCookieStore store = EhApplication.getEhCookieStore(getContext());
List<Cookie> eCookies = store.getCookies(HttpUrl.get(EhUrl.HOST_E));
List<Cookie> exCookies = store.getCookies(HttpUrl.get(EhUrl.HOST_EX));
List<Cookie> cookies = new LinkedList<>(eCookies);
cookies.addAll(exCookies);
String ipbMemberId = null;
String ipbPassHash = null;
String igneous = null;
for (int i = 0, n = cookies.size(); i < n; i++) {
Cookie cookie = cookies.get(i);
switch(cookie.name()) {
case EhCookieStore.KEY_IPD_MEMBER_ID:
ipbMemberId = cookie.value();
break;
case EhCookieStore.KEY_IPD_PASS_HASH:
ipbPassHash = cookie.value();
break;
case EhCookieStore.KEY_IGNEOUS:
igneous = cookie.value();
break;
}
}
if (ipbMemberId != null || ipbPassHash != null || igneous != null) {
message = EhCookieStore.KEY_IPD_MEMBER_ID + ": " + ipbMemberId + "<br>" + EhCookieStore.KEY_IPD_PASS_HASH + ": " + ipbPassHash + "<br>" + EhCookieStore.KEY_IGNEOUS + ": " + igneous;
setDialogMessage(Html.fromHtml(getContext().getString(R.string.settings_eh_identity_cookies_signed, message)));
message = message.replace("<br>", "\n");
} else {
setDialogMessage(getContext().getString(R.string.settings_eh_identity_cookies_tourist));
}
}
use of com.firenio.codec.http11.Cookie in project EhViewer by seven332.
the class CookieRepository method getCookies.
public synchronized List<Cookie> getCookies(HttpUrl url) {
List<Cookie> accepted = new ArrayList<>();
List<Cookie> expired = new ArrayList<>();
for (Map.Entry<String, CookieSet> entry : map.entrySet()) {
String domain = entry.getKey();
CookieSet cookieSet = entry.getValue();
if (domainMatch(url, domain)) {
cookieSet.get(url, accepted, expired);
}
}
for (Cookie cookie : expired) {
if (cookie.persistent()) {
db.remove(cookie);
}
}
// RFC 6265 Section-5.4 step 2, sort the cookie-list
// Cookies with longer paths are listed before cookies with shorter paths.
// Ignore creation-time, we don't store them.
Collections.sort(accepted, new Comparator<Cookie>() {
@Override
public int compare(Cookie o1, Cookie o2) {
return o2.path().length() - o1.path().length();
}
});
return accepted;
}
Aggregations