use of com.firenio.codec.http11.Cookie in project apps-android-wikipedia by wikimedia.
the class SharedPreferenceCookieManager method saveFromResponse.
@Override
public synchronized void saveFromResponse(@NonNull HttpUrl url, @NonNull List<Cookie> cookies) {
if (cookies.isEmpty()) {
return;
}
boolean cookieJarModified = false;
for (Cookie cookie : cookies) {
// Default to the URI's domain if cookie's domain is not explicitly set
String domainSpec = TextUtils.isEmpty(cookie.domain()) ? url.uri().getAuthority() : cookie.domain();
if (!cookieJar.containsKey(domainSpec)) {
cookieJar.put(domainSpec, new ArrayList<>());
}
List<Cookie> cookieList = cookieJar.get(domainSpec);
if (cookie.expiresAt() < System.currentTimeMillis() || "deleted".equals(cookie.value())) {
Iterator<Cookie> i = cookieList.iterator();
while (i.hasNext()) {
if (i.next().name().equals(cookie.name())) {
i.remove();
cookieJarModified = true;
}
}
} else {
Iterator<Cookie> i = cookieList.iterator();
boolean exists = false;
while (i.hasNext()) {
Cookie c = i.next();
if (c.equals(cookie)) {
// an identical cookie already exists, so we don't need to update it.
exists = true;
break;
} else if (c.name().equals(cookie.name())) {
// it's a cookie with the same name, but different contents, so remove the
// current cookie, so that the new one will be added.
i.remove();
}
}
if (!exists) {
cookieList.add(cookie);
cookieJarModified = true;
}
}
}
if (cookieJarModified) {
persistCookies();
}
}
use of com.firenio.codec.http11.Cookie in project baseio by generallycloud.
the class TestCookieHeaderServlet method doAccept.
@Override
protected void doAccept(Channel ch, HttpFrame frame) throws Exception {
String name = frame.getRequestParam("name");
String value = frame.getRequestParam("value");
if (Util.isNullOrBlank(name)) {
name = "test8";
}
if (Util.isNullOrBlank(value)) {
value = Util.randomUUID();
}
String cookieLine = frame.getRequestHeader(HttpHeader.Cookie);
Map<String, String> cookieMap = new HashMap<>();
if (cookieLine != null) {
CookieUtil.parseCookies(cookieMap, cookieLine);
}
String res = "yes server already accept your message :) " + frame.getRequestParams();
res += "<BR/>";
res += cookieMap.toString();
Cookie c = new Cookie(name, value);
c.setComment("comment");
c.setMaxAge(999999);
frame.setContentType(HttpContentType.text_html_utf8);
frame.setResponseHeader(HttpHeader.Set_Cookie, c.toString().getBytes());
frame.setContent(res.getBytes(ch.getCharset()));
ch.writeAndFlush(frame);
}
use of com.firenio.codec.http11.Cookie in project DevRing by LJYcoder.
the class PersistentCookieJar method loadForRequest.
@Override
public synchronized List<Cookie> loadForRequest(HttpUrl url) {
List<Cookie> cookiesToRemove = new ArrayList<>();
List<Cookie> validCookies = new ArrayList<>();
for (Iterator<Cookie> it = cache.iterator(); it.hasNext(); ) {
Cookie currentCookie = it.next();
if (isCookieExpired(currentCookie)) {
cookiesToRemove.add(currentCookie);
it.remove();
} else if (currentCookie.matches(url)) {
validCookies.add(currentCookie);
}
}
persistor.removeAll(cookiesToRemove);
return validCookies;
}
use of com.firenio.codec.http11.Cookie in project DevRing by LJYcoder.
the class SharedPrefsCookiePersistor method removeAll.
@Override
public void removeAll(Collection<Cookie> cookies) {
SharedPreferences.Editor editor = sharedPreferences.edit();
for (Cookie cookie : cookies) {
editor.remove(createCookieKey(cookie));
}
editor.commit();
}
use of com.firenio.codec.http11.Cookie in project EhViewer by seven332.
the class UConfigActivity method onCreate.
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// http://stackoverflow.com/questions/32284642/how-to-handle-an-uncatched-exception
CookieManager cookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.flush();
cookieManager.removeAllCookies(null);
cookieManager.removeSessionCookies(null);
} else {
CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(this);
cookieSyncManager.startSync();
cookieManager.removeAllCookie();
cookieManager.removeSessionCookie();
cookieSyncManager.stopSync();
}
// Copy cookies from okhttp cookie store to CookieManager
url = EhUrl.getUConfigUrl();
EhCookieStore store = EhApplication.getEhCookieStore(this);
for (Cookie cookie : store.getCookies(HttpUrl.parse(url))) {
cookieManager.setCookie(url, cookie.toString());
}
setContentView(R.layout.activity_u_config);
setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new UConfigWebViewClient());
webView.setWebChromeClient(new DialogWebChromeClient(this));
webView.loadUrl(url);
progress = (ProgressView) findViewById(R.id.progress);
Snackbar.make(webView, R.string.apply_tip, Snackbar.LENGTH_LONG).show();
}
Aggregations