/** Adds valid Port attribute value, e.g. "8000,8001,8002" */ @Override protected void formatCookieAsVer(final CharArrayBuffer buffer, final Cookie cookie, int version) { super.formatCookieAsVer(buffer, cookie, version); // format port attribute if (cookie instanceof ClientCookie) { // Test if the port attribute as set by the origin server is not blank String s = ((ClientCookie) cookie).getAttribute(ClientCookie.PORT_ATTR); if (s != null) { buffer.append("; $Port"); buffer.append("=\""); if (s.trim().length() > 0) { int[] ports = cookie.getPorts(); if (ports != null) { for (int i = 0, len = ports.length; i < len; i++) { if (i > 0) { buffer.append(","); } buffer.append(Integer.toString(ports[i])); } } } buffer.append("\""); } } }
public void addCookie(Cookie paramCookie) { String str1 = paramCookie.getName(); this.mCookies.put(str1, paramCookie); SharedPreferences.Editor localEditor = this.mCookiePrefs.edit(); localEditor.putString("names", TextUtils.join(",", this.mCookies.keySet())); localEditor.putString("cookie_" + str1, encodeCookie(new SerializableCookie(paramCookie))); localEditor.commit(); CookieManager localCookieManager = CookieManager.getInstance(); String str2 = paramCookie.getName() + "=" + paramCookie.getValue() + "; domain=" + paramCookie.getDomain(); localCookieManager.setCookie(paramCookie.getDomain(), str2); CookieSyncManager.getInstance().sync(); }
/** * Adds an {@link Cookie HTTP cookie}, replacing any existing equivalent cookies. If the given * cookie has already expired it will not be added, but existing values will still be removed. * * @param cookie the {@link Cookie cookie} to be added * @see #addCookies(Cookie[]) */ public synchronized void addCookie(final Cookie cookie) { if (cookie != null) { // first remove any old cookie that is equivalent cookies.remove(cookie); if (!cookie.isExpired(new Date())) { cookies.add(cookie); } } }