Refine search
String host = origin.getHost(); return new CookieOrigin( host, origin.getPort(), origin.getPath(), origin.isSecure()); } else { return origin;
@Override public boolean match(final Cookie cookie, final CookieOrigin origin) { Args.notNull(cookie, "Cookie"); Args.notNull(origin, "Cookie origin"); final String host = origin.getHost(); final String domain = cookie.getDomain(); if (domain == null) { return false; } return host.endsWith(domain); }
String host = origin.getHost(); String domain = cookie.getDomain(); if (domain == null) { throw new MalformedCookieException("Cookie domain may not be null"); throw new MalformedCookieException( "Illegal domain attribute \"" + domain + "\". Domain of origin: \"" + host + "\""); throw new MalformedCookieException( "Illegal domain attribute \"" + domain + "\". Domain of origin: \"" + host + "\"");
/** * Validate cookie port attribute. If the Port attribute was specified * in header, the request port must be in cookie's port list. */ public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { Args.notNull(cookie, "Cookie"); Args.notNull(origin, "Cookie origin"); final int port = origin.getPort(); if (cookie instanceof ClientCookie && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) { if (!portMatch(port, cookie.getPorts())) { throw new CookieRestrictionViolationException( "Port attribute violates RFC 2965: " + "Request port not found in cookie's port list."); } } }
public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { if (!match(cookie, origin)) { throw new MalformedCookieException( "Illegal path attribute \"" + cookie.getPath() + "\". Path of origin: \"" + origin.getPath() + "\""); } }
@Override public boolean match(Cookie cookie, 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 host = origin.getHost(); String domain = cookie.getDomain(); if (domain == null) { return false; } return host.endsWith(domain); }
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 targetpath = origin.getPath(); String topmostPath = cookie.getPath(); if (topmostPath == null) { topmostPath = "/"; } if (topmostPath.length() > 1 && topmostPath.endsWith("/")) { topmostPath = topmostPath.substring(0, topmostPath.length() - 1); } boolean match = targetpath.startsWith (topmostPath); // if there is a match and these values are not exactly the same we have // to make sure we're not matcing "/foobar" and "/foo" if (match && targetpath.length() != topmostPath.length()) { if (!topmostPath.endsWith("/")) { match = (targetpath.charAt(topmostPath.length()) == '/'); } } return match; }
@Override 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"); } return !cookie.isSecure() || origin.isSecure(); }
/** * Validate cookie port attribute. If the Port attribute was specified * in header, the request port must be in cookie's port list. */ 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"); } int port = origin.getPort(); if (cookie instanceof ClientCookie && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) { if (!portMatch(port, cookie.getPorts())) { throw new MalformedCookieException( "Port attribute violates RFC 2965: " + "Request port not found in cookie's port list."); } } }
public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { if (origin != null && origin.getHost() != null && cookie != null) { String hostPort = origin.getHost() + ":" + origin.getPort(); String domain = cookie.getDomain(); if (hostPort.equals(domain)) { return; } } super.validate(cookie, origin); }
@Override public void validate(Cookie cookie, CookieOrigin origin) throws MalformedCookieException { try { super.validate(cookie, origin); } catch (MalformedCookieException e) { System.err.println("Cookie rejected for url: " + origin.getHost() + (origin.getPort() != 80 ? ":" + origin.getPort() : "") + origin.getPath() + " the error:" + e.getMessage() + " for cookie:" + cookie.toString()); throw e; } } }
private CookieOrigin cookieOriginFromUri(String uri) { try { URL parsedUrl = new URL(uri); int port = parsedUrl.getPort() != -1 ? parsedUrl.getPort() : 80; return new CookieOrigin( parsedUrl.getHost(), port, parsedUrl.getPath(), "https".equals(parsedUrl.getProtocol())); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } } }
CookieOrigin cookieOrigin = new CookieOrigin( hostName, port, boolean needVersionHeader = false; for (Cookie cookie : matchedCookies) { if (ver != cookie.getVersion()) { needVersionHeader = true;
/** * {@inheritDoc} */ @Override public void put(URI uri, Map<String, List<String>> responseHeaders) throws IOException { if (isJavascript(uri.getScheme())) { for (Map.Entry<String, List<String>> entry : responseHeaders.entrySet()) { for (String value : entry.getValue()) { try { List<Cookie> cookies = spec.parse(new BasicHeader(entry.getKey(), value), new CookieOrigin( uri.getHost(), canonicalPort(uri.getScheme(), uri.getPort()), canonicalPath(uri.getPath()), isSecure(uri.getScheme()))); for (Cookie cookie : cookies) { synchronized (store) { store.addCookie(cookie); } } } catch (MalformedCookieException e) { LogsServer.instance().warn( "Malformed cookie for cookie named " + entry.getKey() + ". " + e.getMessage()); } } } } }
/** * Match cookie port attribute. If the Port attribute is not specified * in header, the cookie can be sent to any port. Otherwise, the request port * must be in the cookie's port list. */ 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"); } int port = origin.getPort(); if (cookie instanceof ClientCookie && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) { if (cookie.getPorts() == null) { // Invalid cookie state: port not specified return false; } if (!portMatch(port, cookie.getPorts())) { return false; } } return true; }
private BasicClientCookie createCookie2( final String name, final String value, final CookieOrigin origin) { BasicClientCookie2 cookie = new BasicClientCookie2(name, value); cookie.setPath(getDefaultPath(origin)); cookie.setDomain(getDefaultDomain(origin)); cookie.setPorts(new int [] { origin.getPort() }); return cookie; }
protected static String getDefaultPath(final CookieOrigin origin) { String defaultPath = origin.getPath(); int lastSlashIndex = defaultPath.lastIndexOf('/'); if (lastSlashIndex >= 0) { if (lastSlashIndex == 0) { //Do not remove the very first slash lastSlashIndex = 1; } defaultPath = defaultPath.substring(0, lastSlashIndex); } return defaultPath; }
final String value = headerelement.getValue(); if (name == null || name.isEmpty()) { throw new MalformedCookieException("Cookie name may not be empty"); cookie.setPath(getDefaultPath(origin)); cookie.setDomain(getDefaultDomain(origin)); cookie.setPorts(new int [] { origin.getPort() });