private String normalizePath(final Cookie cookie) { String path = cookie.getPath(); if (path == null) { path = "/"; } if (!path.endsWith("/")) { path = path + "/"; } return path; }
if (c1.getPath() == null && c2.getPath() == null) { return 0; } else if (c1.getPath() == null) { if (c2.getPath().equals(CookieSpec.PATH_DELIM)) { return 0; } else { return -1; } else if (c2.getPath() == null) { if (c1.getPath().equals(CookieSpec.PATH_DELIM)) { return 0; } else { return c1.getPath().compareTo(c2.getPath());
/** * Match cookie path attribute. The value for the Path attribute must be a * prefix of the request-URI (case-sensitive matching). */ public boolean match(final Cookie cookie, final CookieOrigin origin) { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (origin == null) { throw new IllegalArgumentException("Cookie origin may not be null"); } String path = origin.getPath(); if (cookie.getPath() == null) { LOG.warn("Invalid cookie state: path attribute is null."); return false; } if (path.trim().equals("")) { path = PATH_DELIM; } if (!pathMatch(path, cookie.getPath())) { return false; } return true; } }
/** * Validate cookie path attribute. The value for the Path attribute must be a * prefix of the request-URI (case-sensitive matching). */ public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (origin == null) { throw new IllegalArgumentException("Cookie origin may not be null"); } String path = origin.getPath(); if (path == null) { throw new IllegalArgumentException( "Path of origin host may not be null."); } if (cookie.getPath() == null) { throw new MalformedCookieException("Invalid cookie state: " + "path attribute is null."); } if (path.trim().equals("")) { path = PATH_DELIM; } if (!pathMatch(path, cookie.getPath())) { throw new MalformedCookieException( "Illegal path attribute \"" + cookie.getPath() + "\". Path of origin: \"" + path + "\""); } }
/** * Return a string suitable for sending in a <tt>"Cookie"</tt> header * as defined in RFC 2109 for backward compatibility with cookie version 0 * @param buffer The string buffer to use for output * @param cookie The {@link Cookie} to be formatted as string * @param version The version to use. */ private void formatCookieAsVer(final StringBuffer buffer, final Cookie cookie, int version) { String value = cookie.getValue(); if (value == null) { value = ""; } formatParam(buffer, new NameValuePair(cookie.getName(), value), version); if ((cookie.getPath() != null) && cookie.isPathAttributeSpecified()) { buffer.append("; "); formatParam(buffer, new NameValuePair("$Path", cookie.getPath()), version); } if ((cookie.getDomain() != null) && cookie.isDomainAttributeSpecified()) { buffer.append("; "); formatParam(buffer, new NameValuePair("$Domain", cookie.getDomain()), version); } }
private String normalizePath(final Cookie cookie) { String path = cookie.getPath(); if (path == null) { path = "/"; } if (!path.endsWith("/")) { path = path + "/"; } return path; }
private String normalizePath(final Cookie cookie) { String path = cookie.getPath(); if (path == null) { path = "/"; } if (!path.endsWith("/")) { path = path + "/"; } return path; }
private String normalizePath(final Cookie cookie) { String path = cookie.getPath(); if (path == null) { path = "/"; } if (!path.endsWith("/")) { path = path + "/"; } return path; }
private String normalizePath(final Cookie cookie) { String path = cookie.getPath(); if (path == null) { path = "/"; } if (!path.endsWith("/")) { path = path + "/"; } return path; }
/** * Get the cookies for a specific domain and path */ public Cookie[] getCookies(String domain, String path) { Cookie[] cookies = getCookies(); List<Cookie> list = new ArrayList<Cookie>(); for (Cookie cookie : cookies) { String test = cookie.getDomain(); if (test.startsWith(".")) test = test.substring(1); if ((domain.endsWith(test) || test.endsWith(domain)) && (path == null || cookie.getPath().startsWith(path))) { list.add(cookie); } } return list.toArray(new Cookie[list.size()]); }
private static List<List<Pair<String, String>>> convertTokenValues(Map<String, Cookie> values) { List<List<Pair<String, String>>> tokens = new ArrayList<>(); for (Entry<String, Cookie> token : values.entrySet()) { Cookie cookie = token.getValue(); List<Pair<String, String>> fields = new ArrayList<>(); fields.add(new Pair<>("name", token.getKey())); fields.add(new Pair<>("value", cookie.getValue())); fields.add(new Pair<>("domain", cookie.getDomain())); fields.add(new Pair<>("path", cookie.getPath())); fields.add(new Pair<>("secure", Boolean.toString(cookie.getSecure()))); tokens.add(fields); } return tokens; } }
public Set<Cookie> getCookies() { Set<org.apache.commons.httpclient.Cookie> rawCookies = webClient.getCookieManager().getCookies(getHostName()); Set<Cookie> retCookies = new HashSet<Cookie>(); for(org.apache.commons.httpclient.Cookie c : rawCookies) { if (c.getPath() != null && getPath().startsWith(c.getPath())) { retCookies.add(new ReturnedCookie(c.getName(), c.getValue(), c.getDomain(), c.getPath(), c.getExpiryDate(), c.getSecure())); } } return retCookies; }
/** * This method formats the cookie so it can be send from server to client in a * {@linkplain HttpConstants#HEADER_COOKIE_SET "Set-Cookie"} header. */ public static String formatCookieForASetCookieHeader(Cookie cookie) { StringBuffer sb = new StringBuffer(); ServerCookie.appendCookieValue(sb, cookie.getVersion(), cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getDomain(), cookie.getComment(), -1, cookie.getSecure(), false); Date expiryDate = cookie.getExpiryDate(); if (expiryDate != null) { sb.append("; Expires="); sb.append(EXPIRE_FORMATTER.format(expiryDate)); } return sb.toString(); }
/** @deprecated (0.14.0) Use {@link #addCookie(ZestCookie)} instead. */ @Deprecated public void addCookie(Cookie cookie) { addCookie( cookie.getDomain(), cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getExpiryDate(), cookie.getSecure()); }
/** * Return a string suitable for sending in a <tt>"Cookie"</tt> header * as defined in RFC 2109 for backward compatibility with cookie version 0 * @param buffer The string buffer to use for output * @param cookie The {@link Cookie} to be formatted as string * @param version The version to use. */ private void formatCookieAsVer(final StringBuffer buffer, final Cookie cookie, int version) { String value = cookie.getValue(); if (value == null) { value = ""; } formatParam(buffer, new NameValuePair(cookie.getName(), value), version); if ((cookie.getPath() != null) && cookie.isPathAttributeSpecified()) { buffer.append("; "); formatParam(buffer, new NameValuePair("$Path", cookie.getPath()), version); } if ((cookie.getDomain() != null) && cookie.isDomainAttributeSpecified()) { buffer.append("; "); formatParam(buffer, new NameValuePair("$Domain", cookie.getDomain()), version); } }
/** * Return a string suitable for sending in a <tt>"Cookie"</tt> header * as defined in RFC 2109 for backward compatibility with cookie version 0 * @param buffer The string buffer to use for output * @param cookie The {@link Cookie} to be formatted as string * @param version The version to use. */ private void formatCookieAsVer(final StringBuffer buffer, final Cookie cookie, int version) { String value = cookie.getValue(); if (value == null) { value = ""; } formatParam(buffer, new NameValuePair(cookie.getName(), value), version); if ((cookie.getPath() != null) && cookie.isPathAttributeSpecified()) { buffer.append("; "); formatParam(buffer, new NameValuePair("$Path", cookie.getPath()), version); } if ((cookie.getDomain() != null) && cookie.isDomainAttributeSpecified()) { buffer.append("; "); formatParam(buffer, new NameValuePair("$Domain", cookie.getDomain()), version); } }
private void logCookiesAtState(String when) { Cookie[] cookies = getState().getCookies(); if (cookies.length == 0) { Log_OC.d(TAG + " #" + mInstanceNumber, "No cookie at STATE " + when); } else { Log_OC.d(TAG + " #" + mInstanceNumber, "Cookies at STATE (" + when + ")"); for (int i=0; i<cookies.length; i++) { Log_OC.d(TAG + " #" + mInstanceNumber, " (" + i + "):" + "\n name: " + cookies[i].getName() + "\n value: " + cookies[i].getValue() + "\n domain: " + cookies[i].getDomain() + "\n path: " + cookies[i].getPath() ); } } }
private void logCookie(Cookie cookie) { Log_OC.d(TAG, "Cookie name: "+ cookie.getName() ); Log_OC.d(TAG, " value: "+ cookie.getValue() ); Log_OC.d(TAG, " domain: "+ cookie.getDomain()); Log_OC.d(TAG, " path: "+ cookie.getPath() ); Log_OC.d(TAG, " version: "+ cookie.getVersion() ); Log_OC.d(TAG, " expiryDate: " + (cookie.getExpiryDate() != null ? cookie.getExpiryDate().toString() : "--")); Log_OC.d(TAG, " comment: "+ cookie.getComment() ); Log_OC.d(TAG, " secure: "+ cookie.getSecure() ); }