Search in sources :

Example 1 with CookieJar

use of com.laytonsmith.PureUtilities.Web.CookieJar in project CommandHelper by EngineHub.

the class Web method getCookieJar.

private static CookieJar getCookieJar(CArray cookieJar, Target t) {
    CookieJar ret = new CookieJar();
    for (String key : cookieJar.stringKeySet()) {
        CArray cookie = Static.getArray(cookieJar.get(key, t), t);
        String name;
        String value;
        String domain;
        String path;
        long expiration = 0;
        boolean httpOnly = false;
        boolean secureOnly = false;
        if (cookie.containsKey("name") && cookie.containsKey("value") && cookie.containsKey("domain") && cookie.containsKey("path")) {
            name = cookie.get("name", t).val();
            value = cookie.get("value", t).val();
            domain = cookie.get("domain", t).val();
            path = cookie.get("path", t).val();
        } else {
            throw new CREFormatException("The name, value, domain, and path keys are required" + " in all cookies.", t);
        }
        if (cookie.containsKey("expiration")) {
            expiration = Static.getInt(cookie.get("expiration", t), t);
        }
        if (cookie.containsKey("httpOnly")) {
            httpOnly = Static.getBoolean(cookie.get("httpOnly", t), t);
        }
        if (cookie.containsKey("secureOnly")) {
            secureOnly = Static.getBoolean(cookie.get("secureOnly", t), t);
        }
        Cookie c = new Cookie(name, value, domain, path, expiration, httpOnly, secureOnly);
        ret.addCookie(c);
    }
    return ret;
}
Also used : Cookie(com.laytonsmith.PureUtilities.Web.Cookie) CArray(com.laytonsmith.core.constructs.CArray) CookieJar(com.laytonsmith.PureUtilities.Web.CookieJar) CString(com.laytonsmith.core.constructs.CString) CREFormatException(com.laytonsmith.core.exceptions.CRE.CREFormatException)

Aggregations

Cookie (com.laytonsmith.PureUtilities.Web.Cookie)1 CookieJar (com.laytonsmith.PureUtilities.Web.CookieJar)1 CArray (com.laytonsmith.core.constructs.CArray)1 CString (com.laytonsmith.core.constructs.CString)1 CREFormatException (com.laytonsmith.core.exceptions.CRE.CREFormatException)1