Search in sources :

Example 1 with SerializableCookie

use of com.lzy.okgo.cookie.SerializableCookie in project okhttp-OkGo by jeasonlzy.

the class DBCookieStore method loadCookie.

/**
 * 根据当前url获取所有需要的cookie,只返回没有过期的cookie
 */
@Override
public synchronized List<Cookie> loadCookie(HttpUrl url) {
    List<Cookie> ret = new ArrayList<>();
    if (!cookies.containsKey(url.host()))
        return ret;
    List<SerializableCookie> query = CookieManager.getInstance().query("host=?", new String[] { url.host() });
    for (SerializableCookie serializableCookie : query) {
        Cookie cookie = serializableCookie.getCookie();
        if (isCookieExpired(cookie)) {
            removeCookie(url, cookie);
        } else {
            ret.add(cookie);
        }
    }
    return ret;
}
Also used : Cookie(okhttp3.Cookie) SerializableCookie(com.lzy.okgo.cookie.SerializableCookie) ArrayList(java.util.ArrayList) SerializableCookie(com.lzy.okgo.cookie.SerializableCookie)

Example 2 with SerializableCookie

use of com.lzy.okgo.cookie.SerializableCookie in project BaseProject by feer921.

the class DBCookieStore method saveCookie.

@Override
public synchronized void saveCookie(HttpUrl url, Cookie cookie) {
    if (!cookies.containsKey(url.host())) {
        cookies.put(url.host(), new ConcurrentHashMap<String, Cookie>());
    }
    // 当前cookie是否过期
    if (isCookieExpired(cookie)) {
        removeCookie(url, cookie);
    } else {
        // 内存缓存
        cookies.get(url.host()).put(getCookieToken(cookie), cookie);
        // 数据库缓存
        SerializableCookie serializableCookie = new SerializableCookie(url.host(), cookie);
        CookieManager.getInstance().replace(serializableCookie);
    }
}
Also used : Cookie(okhttp3.Cookie) SerializableCookie(com.lzy.okgo.cookie.SerializableCookie) SerializableCookie(com.lzy.okgo.cookie.SerializableCookie)

Example 3 with SerializableCookie

use of com.lzy.okgo.cookie.SerializableCookie in project okhttp-OkGo by jeasonlzy.

the class DBCookieStore method saveCookie.

@Override
public synchronized void saveCookie(HttpUrl url, Cookie cookie) {
    if (!cookies.containsKey(url.host())) {
        cookies.put(url.host(), new ConcurrentHashMap<String, Cookie>());
    }
    // 当前cookie是否过期
    if (isCookieExpired(cookie)) {
        removeCookie(url, cookie);
    } else {
        // 内存缓存
        cookies.get(url.host()).put(getCookieToken(cookie), cookie);
        // 数据库缓存
        SerializableCookie serializableCookie = new SerializableCookie(url.host(), cookie);
        CookieManager.getInstance().replace(serializableCookie);
    }
}
Also used : Cookie(okhttp3.Cookie) SerializableCookie(com.lzy.okgo.cookie.SerializableCookie) SerializableCookie(com.lzy.okgo.cookie.SerializableCookie)

Example 4 with SerializableCookie

use of com.lzy.okgo.cookie.SerializableCookie in project BaseProject by feer921.

the class DBCookieStore method loadCookie.

/**
 * 根据当前url获取所有需要的cookie,只返回没有过期的cookie
 */
@Override
public synchronized List<Cookie> loadCookie(HttpUrl url) {
    List<Cookie> ret = new ArrayList<>();
    if (!cookies.containsKey(url.host()))
        return ret;
    List<SerializableCookie> query = CookieManager.getInstance().query("host=?", new String[] { url.host() });
    for (SerializableCookie serializableCookie : query) {
        Cookie cookie = serializableCookie.getCookie();
        if (isCookieExpired(cookie)) {
            removeCookie(url, cookie);
        } else {
            ret.add(cookie);
        }
    }
    return ret;
}
Also used : Cookie(okhttp3.Cookie) SerializableCookie(com.lzy.okgo.cookie.SerializableCookie) ArrayList(java.util.ArrayList) SerializableCookie(com.lzy.okgo.cookie.SerializableCookie)

Aggregations

SerializableCookie (com.lzy.okgo.cookie.SerializableCookie)4 Cookie (okhttp3.Cookie)4 ArrayList (java.util.ArrayList)2