/** * 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("\""); } } }
/** * validate cookie version attribute. Version attribute is REQUIRED. */ public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (cookie instanceof SetCookie2) { if (cookie instanceof ClientCookie && !((ClientCookie) cookie).containsAttribute(ClientCookie.VERSION_ATTR)) { throw new MalformedCookieException( "Violates RFC 2965. Version attribute is required."); } } }
/** * Returns the domain to which this cookie applies ({@code null} for all domains). * @return the domain to which this cookie applies ({@code null} for all domains) */ public String getDomain() { return httpClientCookie_.getDomain(); }
/** * Returns the date on which this cookie expires ({@code null} if it never expires). * @return the date on which this cookie expires ({@code null} if it never expires) */ public Date getExpires() { return httpClientCookie_.getExpiryDate(); }
/** * Returns the domain to which this cookie applies ({@code null} for all domains). * @return the domain to which this cookie applies ({@code null} for all domains) */ public String getDomain() { return httpClientCookie_.getDomain(); }
/** * Returns the date on which this cookie expires ({@code null} if it never expires). * @return the date on which this cookie expires ({@code null} if it never expires) */ public Date getExpires() { return httpClientCookie_.getExpiryDate(); }
/** * 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."); } } }
/** * Returns whether or not this cookie is HttpOnly (i.e. not available in JS). * @see <a href="http://en.wikipedia.org/wiki/HTTP_cookie#Secure_and_HttpOnly">Wikipedia</a> * @return whether or not this cookie is HttpOnly (i.e. not available in JS). */ public boolean isHttpOnly() { return httpClientCookie_.getAttribute("httponly") != null; }
/** * 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; }
/** * Returns whether or not this cookie is HttpOnly (i.e. not available in JS). * @see <a href="http://en.wikipedia.org/wiki/HTTP_cookie#Secure_and_HttpOnly">Wikipedia</a> * @return whether or not this cookie is HttpOnly (i.e. not available in JS). */ public boolean isHttpOnly() { return httpClientCookie_.getAttribute("httponly") != null; }
&& ((ClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)) {
/** * 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("\""); } } }
/** * 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 char array buffer to use for output * @param cookie The {@link Cookie} to be formatted as string * @param version The version to use. */ protected void formatCookieAsVer(final CharArrayBuffer buffer, final Cookie cookie, int version) { formatParamAsVer(buffer, cookie.getName(), cookie.getValue(), version); if (cookie.getPath() != null) { if (cookie instanceof ClientCookie && ((ClientCookie) cookie).containsAttribute(ClientCookie.PATH_ATTR)) { buffer.append("; "); formatParamAsVer(buffer, "$Path", cookie.getPath(), version); } } if (cookie.getDomain() != null) { if (cookie instanceof ClientCookie && ((ClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)) { buffer.append("; "); formatParamAsVer(buffer, "$Domain", cookie.getDomain(), version); } } }
/** * Adds valid Port attribute value, e.g. "8000,8001,8002" */ @Override protected void formatCookieAsVer(final CharArrayBuffer buffer, final Cookie cookie, final 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 final String s = ((ClientCookie) cookie).getAttribute(ClientCookie.PORT_ATTR); if (s != null) { buffer.append("; $Port"); buffer.append("=\""); if (!s.trim().isEmpty()) { final int[] ports = cookie.getPorts(); if (ports != null) { final int len = ports.length; for (int i = 0; i < len; i++) { if (i > 0) { buffer.append(","); } buffer.append(Integer.toString(ports[i])); } } } buffer.append("\""); } } }
/** * validate cookie version attribute. Version attribute is REQUIRED. */ public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (cookie instanceof SetCookie2) { if (cookie instanceof ClientCookie && !((ClientCookie) cookie).containsAttribute(ClientCookie.VERSION_ATTR)) { throw new MalformedCookieException( "Violates RFC 2965. Version attribute is required."); } } }
/** * 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("\""); } } }
/** * validate cookie version attribute. Version attribute is REQUIRED. */ public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (cookie instanceof SetCookie2) { if (cookie instanceof ClientCookie && !((ClientCookie) cookie).containsAttribute(ClientCookie.VERSION_ATTR)) { throw new MalformedCookieException( "Violates RFC 2965. Version attribute is required."); } } }
/** * 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("\""); } } }
/** * validate cookie version attribute. Version attribute is REQUIRED. */ public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException { if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (cookie instanceof SetCookie2) { if (cookie instanceof ClientCookie && !((ClientCookie) cookie).containsAttribute(ClientCookie.VERSION_ATTR)) { throw new MalformedCookieException( "Violates RFC 2965. Version attribute is required."); } } }
/** * Adds valid Port attribute value, e.g. "8000,8001,8002" */ @Override protected void formatCookieAsVer(final CharArrayBuffer buffer, final Cookie cookie, final 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 final String s = ((ClientCookie) cookie).getAttribute(ClientCookie.PORT_ATTR); if (s != null) { buffer.append("; $Port"); buffer.append("=\""); if (s.trim().length() > 0) { final int[] ports = cookie.getPorts(); if (ports != null) { final int len = ports.length; for (int i = 0; i < len; i++) { if (i > 0) { buffer.append(","); } buffer.append(Integer.toString(ports[i])); } } } buffer.append("\""); } } }