diff options
Diffstat (limited to 'src/org/apache/http/impl/cookie')
33 files changed, 0 insertions, 3869 deletions
diff --git a/src/org/apache/http/impl/cookie/AbstractCookieAttributeHandler.java b/src/org/apache/http/impl/cookie/AbstractCookieAttributeHandler.java deleted file mode 100644 index 1aa4d2c..0000000 --- a/src/org/apache/http/impl/cookie/AbstractCookieAttributeHandler.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/AbstractCookieAttributeHandler.java $ - * $Revision: 503525 $ - * $Date: 2007-02-04 17:15:08 -0800 (Sun, 04 Feb 2007) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ -package org.apache.http.impl.cookie; - -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieAttributeHandler; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.MalformedCookieException; - -public abstract class AbstractCookieAttributeHandler implements CookieAttributeHandler { - - public void validate(final Cookie cookie, final CookieOrigin origin) - throws MalformedCookieException { - // Do nothing - } - - public boolean match(final Cookie cookie, final CookieOrigin origin) { - // Always match - return true; - } - -} diff --git a/src/org/apache/http/impl/cookie/AbstractCookieSpec.java b/src/org/apache/http/impl/cookie/AbstractCookieSpec.java deleted file mode 100644 index 3e47a4d..0000000 --- a/src/org/apache/http/impl/cookie/AbstractCookieSpec.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/AbstractCookieSpec.java $ - * $Revision: 617207 $ - * $Date: 2008-01-31 12:14:12 -0800 (Thu, 31 Jan 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.apache.http.cookie.CookieAttributeHandler; -import org.apache.http.cookie.CookieSpec; - -/** - * Abstract cookie specification which can delegate the job of parsing, - * validation or matching cookie attributes to a number of arbitrary - * {@link CookieAttributeHandler}s. - * - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * - * @since 4.0 - */ -public abstract class AbstractCookieSpec implements CookieSpec { - - /** - * Stores attribute name -> attribute handler mappings - */ - private final Map<String, CookieAttributeHandler> attribHandlerMap; - - /** - * Default constructor - * */ - public AbstractCookieSpec() { - super(); - this.attribHandlerMap = new HashMap<String, CookieAttributeHandler>(10); - } - - public void registerAttribHandler( - final String name, final CookieAttributeHandler handler) { - if (name == null) { - throw new IllegalArgumentException("Attribute name may not be null"); - } - if (handler == null) { - throw new IllegalArgumentException("Attribute handler may not be null"); - } - this.attribHandlerMap.put(name, handler); - } - - /** - * Finds an attribute handler {@link CookieAttributeHandler} for the - * given attribute. Returns <tt>null</tt> if no attribute handler is - * found for the specified attribute. - * - * @param name attribute name. e.g. Domain, Path, etc. - * @return an attribute handler or <tt>null</tt> - */ - protected CookieAttributeHandler findAttribHandler(final String name) { - return this.attribHandlerMap.get(name); - } - - /** - * Gets attribute handler {@link CookieAttributeHandler} for the - * given attribute. - * - * @param name attribute name. e.g. Domain, Path, etc. - * @throws IllegalStateException if handler not found for the - * specified attribute. - */ - protected CookieAttributeHandler getAttribHandler(final String name) { - CookieAttributeHandler handler = findAttribHandler(name); - if (handler == null) { - throw new IllegalStateException("Handler not registered for " + - name + " attribute."); - } else { - return handler; - } - } - - protected Collection<CookieAttributeHandler> getAttribHandlers() { - return this.attribHandlerMap.values(); - } - -} diff --git a/src/org/apache/http/impl/cookie/BasicClientCookie.java b/src/org/apache/http/impl/cookie/BasicClientCookie.java deleted file mode 100644 index 6ec6c2b..0000000 --- a/src/org/apache/http/impl/cookie/BasicClientCookie.java +++ /dev/null @@ -1,376 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java $ - * $Revision: 659191 $ - * $Date: 2008-05-22 11:26:53 -0700 (Thu, 22 May 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import java.util.Date; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -import org.apache.http.cookie.ClientCookie; -import org.apache.http.cookie.SetCookie; - -/** - * HTTP "magic-cookie" represents a piece of state information - * that the HTTP agent and the target server can exchange to maintain - * a session. - * - * @author B.C. Holmes - * @author <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a> - * @author <a href="mailto:dsale@us.britannica.com">Doug Sale</a> - * @author Rod Waldhoff - * @author dIon Gillard - * @author Sean C. Sullivan - * @author <a href="mailto:JEvans@Cyveillance.com">John Evans</a> - * @author Marc A. Saegesser - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a> - * - * @version $Revision: 659191 $ - */ -public class BasicClientCookie implements SetCookie, ClientCookie, Cloneable { - - /** - * Default Constructor taking a name and a value. The value may be null. - * - * @param name The name. - * @param value The value. - */ - public BasicClientCookie(final String name, final String value) { - super(); - if (name == null) { - throw new IllegalArgumentException("Name may not be null"); - } - this.name = name; - this.attribs = new HashMap<String, String>(); - this.value = value; - } - - /** - * Returns the name. - * - * @return String name The name - */ - public String getName() { - return this.name; - } - - /** - * Returns the value. - * - * @return String value The current value. - */ - public String getValue() { - return this.value; - } - - /** - * Sets the value - * - * @param value - */ - public void setValue(final String value) { - this.value = value; - } - - /** - * Returns the comment describing the purpose of this cookie, or - * <tt>null</tt> if no such comment has been defined. - * - * @return comment - * - * @see #setComment(String) - */ - public String getComment() { - return cookieComment; - } - - /** - * If a user agent (web browser) presents this cookie to a user, the - * cookie's purpose will be described using this comment. - * - * @param comment - * - * @see #getComment() - */ - public void setComment(String comment) { - cookieComment = comment; - } - - - /** - * Returns null. Cookies prior to RFC2965 do not set this attribute - */ - public String getCommentURL() { - return null; - } - - - /** - * Returns the expiration {@link Date} of the cookie, or <tt>null</tt> - * if none exists. - * <p><strong>Note:</strong> the object returned by this method is - * considered immutable. Changing it (e.g. using setTime()) could result - * in undefined behaviour. Do so at your peril. </p> - * @return Expiration {@link Date}, or <tt>null</tt>. - * - * @see #setExpiryDate(java.util.Date) - * - */ - public Date getExpiryDate() { - return cookieExpiryDate; - } - - /** - * Sets expiration date. - * <p><strong>Note:</strong> the object returned by this method is considered - * immutable. Changing it (e.g. using setTime()) could result in undefined - * behaviour. Do so at your peril.</p> - * - * @param expiryDate the {@link Date} after which this cookie is no longer valid. - * - * @see #getExpiryDate - * - */ - public void setExpiryDate (Date expiryDate) { - cookieExpiryDate = expiryDate; - } - - - /** - * Returns <tt>false</tt> if the cookie should be discarded at the end - * of the "session"; <tt>true</tt> otherwise. - * - * @return <tt>false</tt> if the cookie should be discarded at the end - * of the "session"; <tt>true</tt> otherwise - */ - public boolean isPersistent() { - return (null != cookieExpiryDate); - } - - - /** - * Returns domain attribute of the cookie. - * - * @return the value of the domain attribute - * - * @see #setDomain(java.lang.String) - */ - public String getDomain() { - return cookieDomain; - } - - /** - * Sets the domain attribute. - * - * @param domain The value of the domain attribute - * - * @see #getDomain - */ - public void setDomain(String domain) { - if (domain != null) { - cookieDomain = domain.toLowerCase(Locale.ENGLISH); - } else { - cookieDomain = null; - } - } - - - /** - * Returns the path attribute of the cookie - * - * @return The value of the path attribute. - * - * @see #setPath(java.lang.String) - */ - public String getPath() { - return cookiePath; - } - - /** - * Sets the path attribute. - * - * @param path The value of the path attribute - * - * @see #getPath - * - */ - public void setPath(String path) { - cookiePath = path; - } - - /** - * @return <code>true</code> if this cookie should only be sent over secure connections. - * @see #setSecure(boolean) - */ - public boolean isSecure() { - return isSecure; - } - - /** - * Sets the secure attribute of the cookie. - * <p> - * When <tt>true</tt> the cookie should only be sent - * using a secure protocol (https). This should only be set when - * the cookie's originating server used a secure protocol to set the - * cookie's value. - * - * @param secure The value of the secure attribute - * - * @see #isSecure() - */ - public void setSecure (boolean secure) { - isSecure = secure; - } - - - /** - * Returns null. Cookies prior to RFC2965 do not set this attribute - */ - public int[] getPorts() { - return null; - } - - - /** - * Returns the version of the cookie specification to which this - * cookie conforms. - * - * @return the version of the cookie. - * - * @see #setVersion(int) - * - */ - public int getVersion() { - return cookieVersion; - } - - /** - * Sets the version of the cookie specification to which this - * cookie conforms. - * - * @param version the version of the cookie. - * - * @see #getVersion - */ - public void setVersion(int version) { - cookieVersion = version; - } - - /** - * Returns true if this cookie has expired. - * @param date Current time - * - * @return <tt>true</tt> if the cookie has expired. - */ - public boolean isExpired(final Date date) { - if (date == null) { - throw new IllegalArgumentException("Date may not be null"); - } - return (cookieExpiryDate != null - && cookieExpiryDate.getTime() <= date.getTime()); - } - - public void setAttribute(final String name, final String value) { - this.attribs.put(name, value); - } - - public String getAttribute(final String name) { - return this.attribs.get(name); - } - - public boolean containsAttribute(final String name) { - return this.attribs.get(name) != null; - } - - @Override - public Object clone() throws CloneNotSupportedException { - BasicClientCookie clone = (BasicClientCookie) super.clone(); - clone.attribs = new HashMap<String, String>(this.attribs); - return clone; - } - - @Override - public String toString() { - StringBuilder buffer = new StringBuilder(); - buffer.append("[version: "); - buffer.append(Integer.toString(this.cookieVersion)); - buffer.append("]"); - buffer.append("[name: "); - buffer.append(this.name); - buffer.append("]"); - buffer.append("[value: "); - buffer.append(this.value); - buffer.append("]"); - buffer.append("[domain: "); - buffer.append(this.cookieDomain); - buffer.append("]"); - buffer.append("[path: "); - buffer.append(this.cookiePath); - buffer.append("]"); - buffer.append("[expiry: "); - buffer.append(this.cookieExpiryDate); - buffer.append("]"); - return buffer.toString(); - } - - // ----------------------------------------------------- Instance Variables - - /** Cookie name */ - private final String name; - - /** Cookie attributes as specified by the origin server */ - private Map<String, String> attribs; - - /** Cookie value */ - private String value; - - /** Comment attribute. */ - private String cookieComment; - - /** Domain attribute. */ - private String cookieDomain; - - /** Expiration {@link Date}. */ - private Date cookieExpiryDate; - - /** Path attribute. */ - private String cookiePath; - - /** My secure flag. */ - private boolean isSecure; - - /** The version of the cookie specification I was created from. */ - private int cookieVersion; - -} - diff --git a/src/org/apache/http/impl/cookie/BasicClientCookie2.java b/src/org/apache/http/impl/cookie/BasicClientCookie2.java deleted file mode 100644 index 86ec60d..0000000 --- a/src/org/apache/http/impl/cookie/BasicClientCookie2.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BasicClientCookie2.java $ - * $Revision: 659191 $ - * $Date: 2008-05-22 11:26:53 -0700 (Thu, 22 May 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import java.util.Date; - -import org.apache.http.cookie.SetCookie2; - -/** - * HTTP "magic-cookie" represents a piece of state information - * that the HTTP agent and the target server can exchange to maintain - * a session as specified by RFC2965. - * - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - */ -public class BasicClientCookie2 extends BasicClientCookie implements SetCookie2 { - - private String commentURL; - private int[] ports; - private boolean discard; - - /** - * Default Constructor taking a name and a value. The value may be null. - * - * @param name The name. - * @param value The value. - */ - public BasicClientCookie2(final String name, final String value) { - super(name, value); - } - - @Override - public int[] getPorts() { - return this.ports; - } - - public void setPorts(final int[] ports) { - this.ports = ports; - } - - @Override - public String getCommentURL() { - return this.commentURL; - } - - public void setCommentURL(final String commentURL) { - this.commentURL = commentURL; - } - - public void setDiscard(boolean discard) { - this.discard = discard; - } - - @Override - public boolean isPersistent() { - return !this.discard && super.isPersistent(); - } - - @Override - public boolean isExpired(final Date date) { - return this.discard || super.isExpired(date); - } - - @Override - public Object clone() throws CloneNotSupportedException { - BasicClientCookie2 clone = (BasicClientCookie2) super.clone(); - clone.ports = this.ports.clone(); - return clone; - } - -} - diff --git a/src/org/apache/http/impl/cookie/BasicCommentHandler.java b/src/org/apache/http/impl/cookie/BasicCommentHandler.java deleted file mode 100644 index ce8baea..0000000 --- a/src/org/apache/http/impl/cookie/BasicCommentHandler.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BasicCommentHandler.java $ - * $Revision: 558519 $ - * $Date: 2007-07-22 11:19:49 -0700 (Sun, 22 Jul 2007) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ -package org.apache.http.impl.cookie; - -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SetCookie; - -public class BasicCommentHandler extends AbstractCookieAttributeHandler { - - public BasicCommentHandler() { - super(); - } - - public void parse(final SetCookie cookie, final String value) - throws MalformedCookieException { - if (cookie == null) { - throw new IllegalArgumentException("Cookie may not be null"); - } - cookie.setComment(value); - } - -} diff --git a/src/org/apache/http/impl/cookie/BasicDomainHandler.java b/src/org/apache/http/impl/cookie/BasicDomainHandler.java deleted file mode 100644 index 267faf8..0000000 --- a/src/org/apache/http/impl/cookie/BasicDomainHandler.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BasicDomainHandler.java $ - * $Revision: 653041 $ - * $Date: 2008-05-03 03:39:28 -0700 (Sat, 03 May 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ -package org.apache.http.impl.cookie; - -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieAttributeHandler; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SetCookie; - -public class BasicDomainHandler implements CookieAttributeHandler { - - public BasicDomainHandler() { - super(); - } - - public void parse(final SetCookie cookie, final String value) - throws MalformedCookieException { - if (cookie == null) { - throw new IllegalArgumentException("Cookie may not be null"); - } - if (value == null) { - throw new MalformedCookieException("Missing value for domain attribute"); - } - if (value.trim().length() == 0) { - throw new MalformedCookieException("Blank value for domain attribute"); - } - cookie.setDomain(value); - } - - 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"); - } - // Validate the cookies domain attribute. NOTE: Domains without - // any dots are allowed to support hosts on private LANs that don't - // have DNS names. Since they have no dots, to domain-match the - // request-host and domain must be identical for the cookie to sent - // back to the origin-server. - String host = origin.getHost(); - String domain = cookie.getDomain(); - if (domain == null) { - throw new MalformedCookieException("Cookie domain may not be null"); - } - if (host.contains(".")) { - // Not required to have at least two dots. RFC 2965. - // A Set-Cookie2 with Domain=ajax.com will be accepted. - - // domain must match host - if (!host.endsWith(domain)) { - if (domain.startsWith(".")) { - domain = domain.substring(1, domain.length()); - } - if (!host.equals(domain)) { - throw new MalformedCookieException( - "Illegal domain attribute \"" + domain - + "\". Domain of origin: \"" + host + "\""); - } - } - } else { - if (!host.equals(domain)) { - throw new MalformedCookieException( - "Illegal domain attribute \"" + domain - + "\". Domain of origin: \"" + host + "\""); - } - } - } - - 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 host = origin.getHost(); - String domain = cookie.getDomain(); - if (domain == null) { - return false; - } - if (host.equals(domain)) { - return true; - } - if (!domain.startsWith(".")) { - domain = '.' + domain; - } - return host.endsWith(domain) || host.equals(domain.substring(1)); - } - -} diff --git a/src/org/apache/http/impl/cookie/BasicExpiresHandler.java b/src/org/apache/http/impl/cookie/BasicExpiresHandler.java deleted file mode 100644 index a53519e..0000000 --- a/src/org/apache/http/impl/cookie/BasicExpiresHandler.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BasicExpiresHandler.java $ - * $Revision: 558519 $ - * $Date: 2007-07-22 11:19:49 -0700 (Sun, 22 Jul 2007) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ -package org.apache.http.impl.cookie; - -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SetCookie; - - -public class BasicExpiresHandler extends AbstractCookieAttributeHandler { - - /** Valid date patterns */ - private final String[] datepatterns; - - public BasicExpiresHandler(final String[] datepatterns) { - if (datepatterns == null) { - throw new IllegalArgumentException("Array of date patterns may not be null"); - } - this.datepatterns = datepatterns; - } - - public void parse(final SetCookie cookie, final String value) - throws MalformedCookieException { - if (cookie == null) { - throw new IllegalArgumentException("Cookie may not be null"); - } - if (value == null) { - throw new MalformedCookieException("Missing value for expires attribute"); - } - try { - cookie.setExpiryDate(DateUtils.parseDate(value, this.datepatterns)); - } catch (DateParseException dpe) { - throw new MalformedCookieException("Unable to parse expires attribute: " - + value); - } - } - -} diff --git a/src/org/apache/http/impl/cookie/BasicMaxAgeHandler.java b/src/org/apache/http/impl/cookie/BasicMaxAgeHandler.java deleted file mode 100644 index 92a5c7d..0000000 --- a/src/org/apache/http/impl/cookie/BasicMaxAgeHandler.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BasicMaxAgeHandler.java $ - * $Revision: 581953 $ - * $Date: 2007-10-04 08:53:50 -0700 (Thu, 04 Oct 2007) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ -package org.apache.http.impl.cookie; - -import java.util.Date; - -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SetCookie; - -public class BasicMaxAgeHandler extends AbstractCookieAttributeHandler { - - public BasicMaxAgeHandler() { - super(); - } - - public void parse(final SetCookie cookie, final String value) - throws MalformedCookieException { - if (cookie == null) { - throw new IllegalArgumentException("Cookie may not be null"); - } - if (value == null) { - throw new MalformedCookieException("Missing value for max-age attribute"); - } - int age; - try { - age = Integer.parseInt(value); - } catch (NumberFormatException e) { - throw new MalformedCookieException ("Invalid max-age attribute: " - + value); - } - if (age < 0) { - throw new MalformedCookieException ("Negative max-age attribute: " - + value); - } - cookie.setExpiryDate(new Date(System.currentTimeMillis() + age * 1000L)); - } - -} diff --git a/src/org/apache/http/impl/cookie/BasicPathHandler.java b/src/org/apache/http/impl/cookie/BasicPathHandler.java deleted file mode 100644 index 43a12c8..0000000 --- a/src/org/apache/http/impl/cookie/BasicPathHandler.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BasicPathHandler.java $ - * $Revision: 653041 $ - * $Date: 2008-05-03 03:39:28 -0700 (Sat, 03 May 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ -package org.apache.http.impl.cookie; - -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieAttributeHandler; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SetCookie; - -public class BasicPathHandler implements CookieAttributeHandler { - - public BasicPathHandler() { - super(); - } - - public void parse(final SetCookie cookie, String value) - throws MalformedCookieException { - if (cookie == null) { - throw new IllegalArgumentException("Cookie may not be null"); - } - if (value == null || value.trim().length() == 0) { - value = "/"; - } - cookie.setPath(value); - } - - 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() + "\""); - } - } - - 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; - } - -} diff --git a/src/org/apache/http/impl/cookie/BasicSecureHandler.java b/src/org/apache/http/impl/cookie/BasicSecureHandler.java deleted file mode 100644 index 9100b9c..0000000 --- a/src/org/apache/http/impl/cookie/BasicSecureHandler.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BasicSecureHandler.java $ - * $Revision: 653041 $ - * $Date: 2008-05-03 03:39:28 -0700 (Sat, 03 May 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ -package org.apache.http.impl.cookie; - -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SetCookie; - -public class BasicSecureHandler extends AbstractCookieAttributeHandler { - - public BasicSecureHandler() { - super(); - } - - public void parse(final SetCookie cookie, final String value) - throws MalformedCookieException { - if (cookie == null) { - throw new IllegalArgumentException("Cookie may not be null"); - } - cookie.setSecure(true); - } - - @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(); - } - -} diff --git a/src/org/apache/http/impl/cookie/BestMatchSpec.java b/src/org/apache/http/impl/cookie/BestMatchSpec.java deleted file mode 100644 index e33fec3..0000000 --- a/src/org/apache/http/impl/cookie/BestMatchSpec.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java $ - * $Revision: 657334 $ - * $Date: 2008-05-17 04:44:16 -0700 (Sat, 17 May 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import java.util.List; - -import org.apache.http.Header; -import org.apache.http.HeaderElement; -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.CookieSpec; -import org.apache.http.cookie.MalformedCookieException; - -/** - * 'Meta' cookie specification that selects a cookie policy depending - * on the format of the cookie(s) - * - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * - * @since 4.0 - */ -public class BestMatchSpec implements CookieSpec { - - private final String[] datepatterns; - private final boolean oneHeader; - - private RFC2965Spec strict; - private BrowserCompatSpec compat; - private NetscapeDraftSpec netscape; - - public BestMatchSpec(final String[] datepatterns, boolean oneHeader) { - super(); - this.datepatterns = datepatterns; - this.oneHeader = oneHeader; - } - - public BestMatchSpec() { - this(null, false); - } - - private RFC2965Spec getStrict() { - if (this.strict == null) { - this.strict = new RFC2965Spec(this.datepatterns, this.oneHeader); - } - return strict; - } - - private BrowserCompatSpec getCompat() { - if (this.compat == null) { - this.compat = new BrowserCompatSpec(this.datepatterns); - } - return compat; - } - - private NetscapeDraftSpec getNetscape() { - if (this.netscape == null) { - String[] patterns = this.datepatterns; - if (patterns == null) { - patterns = BrowserCompatSpec.DATE_PATTERNS; - } - this.netscape = new NetscapeDraftSpec(patterns); - } - return netscape; - } - - public List<Cookie> parse( - final Header header, - final CookieOrigin origin) throws MalformedCookieException { - if (header == null) { - throw new IllegalArgumentException("Header may not be null"); - } - if (origin == null) { - throw new IllegalArgumentException("Cookie origin may not be null"); - } - HeaderElement[] helems = header.getElements(); - boolean versioned = false; - boolean netscape = false; - for (HeaderElement helem: helems) { - if (helem.getParameterByName("version") != null) { - versioned = true; - } - if (helem.getParameterByName("expires") != null) { - netscape = true; - } - } - if (netscape) { - - } - // Do we have a cookie with a version attribute? - if (versioned) { - return getStrict().parse(helems, origin); - } else if (netscape) { - // Need to parse the header again, - // because Netscape draft cannot handle - // comma separators - return getNetscape().parse(header, origin); - } else { - return getCompat().parse(helems, origin); - } - } - - 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"); - } - if (cookie.getVersion() > 0) { - getStrict().validate(cookie, origin); - } else { - getCompat().validate(cookie, origin); - } - } - - 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"); - } - if (cookie.getVersion() > 0) { - return getStrict().match(cookie, origin); - } else { - return getCompat().match(cookie, origin); - } - } - - public List<Header> formatCookies(final List<Cookie> cookies) { - if (cookies == null) { - throw new IllegalArgumentException("List of cookie may not be null"); - } - int version = Integer.MAX_VALUE; - for (Cookie cookie: cookies) { - if (cookie.getVersion() < version) { - version = cookie.getVersion(); - } - } - if (version > 0) { - return getStrict().formatCookies(cookies); - } else { - return getCompat().formatCookies(cookies); - } - } - - public int getVersion() { - return getStrict().getVersion(); - } - - public Header getVersionHeader() { - return getStrict().getVersionHeader(); - } - -}
\ No newline at end of file diff --git a/src/org/apache/http/impl/cookie/BestMatchSpecFactory.java b/src/org/apache/http/impl/cookie/BestMatchSpecFactory.java deleted file mode 100644 index cb632bb..0000000 --- a/src/org/apache/http/impl/cookie/BestMatchSpecFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BestMatchSpecFactory.java $ - * $Revision: 613707 $ - * $Date: 2008-01-20 16:28:37 -0800 (Sun, 20 Jan 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import org.apache.http.cookie.CookieSpec; -import org.apache.http.cookie.CookieSpecFactory; -import org.apache.http.cookie.params.CookieSpecPNames; -import org.apache.http.params.HttpParams; - -/** - * - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * - * @since 4.0 - */ -public class BestMatchSpecFactory implements CookieSpecFactory { - - public CookieSpec newInstance(final HttpParams params) { - if (params != null) { - return new BestMatchSpec( - (String []) params.getParameter(CookieSpecPNames.DATE_PATTERNS), - params.getBooleanParameter(CookieSpecPNames.SINGLE_COOKIE_HEADER, false)); - } else { - return new BestMatchSpec(); - } - } - -} diff --git a/src/org/apache/http/impl/cookie/BrowserCompatSpec.java b/src/org/apache/http/impl/cookie/BrowserCompatSpec.java deleted file mode 100644 index d7bc0da..0000000 --- a/src/org/apache/http/impl/cookie/BrowserCompatSpec.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java $ - * $Revision: 657334 $ - * $Date: 2008-05-17 04:44:16 -0700 (Sat, 17 May 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -import org.apache.http.FormattedHeader; -import org.apache.http.Header; -import org.apache.http.HeaderElement; -import org.apache.http.cookie.ClientCookie; -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SM; -import org.apache.http.message.BufferedHeader; -import org.apache.http.message.ParserCursor; -import org.apache.http.util.CharArrayBuffer; - -/** - * Cookie specification that strives to closely mimic (mis)behavior of - * common web browser applications such as Microsoft Internet Explorer - * and Mozilla FireFox. - * - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * - * @since 4.0 - */ -public class BrowserCompatSpec extends CookieSpecBase { - - /** Valid date patterns used per default */ - protected static final String[] DATE_PATTERNS = new String[] { - DateUtils.PATTERN_RFC1123, - DateUtils.PATTERN_RFC1036, - DateUtils.PATTERN_ASCTIME, - "EEE, dd-MMM-yyyy HH:mm:ss z", - "EEE, dd-MMM-yyyy HH-mm-ss z", - "EEE, dd MMM yy HH:mm:ss z", - "EEE dd-MMM-yyyy HH:mm:ss z", - "EEE dd MMM yyyy HH:mm:ss z", - "EEE dd-MMM-yyyy HH-mm-ss z", - "EEE dd-MMM-yy HH:mm:ss z", - "EEE dd MMM yy HH:mm:ss z", - "EEE,dd-MMM-yy HH:mm:ss z", - "EEE,dd-MMM-yyyy HH:mm:ss z", - "EEE, dd-MM-yyyy HH:mm:ss z", - }; - - private final String[] datepatterns; - - /** Default constructor */ - public BrowserCompatSpec(final String[] datepatterns) { - super(); - if (datepatterns != null) { - this.datepatterns = datepatterns.clone(); - } else { - this.datepatterns = DATE_PATTERNS; - } - registerAttribHandler(ClientCookie.PATH_ATTR, new BasicPathHandler()); - registerAttribHandler(ClientCookie.DOMAIN_ATTR, new BasicDomainHandler()); - registerAttribHandler(ClientCookie.MAX_AGE_ATTR, new BasicMaxAgeHandler()); - registerAttribHandler(ClientCookie.SECURE_ATTR, new BasicSecureHandler()); - registerAttribHandler(ClientCookie.COMMENT_ATTR, new BasicCommentHandler()); - registerAttribHandler(ClientCookie.EXPIRES_ATTR, new BasicExpiresHandler( - this.datepatterns)); - } - - /** Default constructor */ - public BrowserCompatSpec() { - this(null); - } - - public List<Cookie> parse(final Header header, final CookieOrigin origin) - throws MalformedCookieException { - if (header == null) { - throw new IllegalArgumentException("Header may not be null"); - } - if (origin == null) { - throw new IllegalArgumentException("Cookie origin may not be null"); - } - String headervalue = header.getValue(); - boolean isNetscapeCookie = false; - int i1 = headervalue.toLowerCase(Locale.ENGLISH).indexOf("expires="); - if (i1 != -1) { - i1 += "expires=".length(); - int i2 = headervalue.indexOf(';', i1); - if (i2 == -1) { - i2 = headervalue.length(); - } - try { - DateUtils.parseDate(headervalue.substring(i1, i2), this.datepatterns); - isNetscapeCookie = true; - } catch (DateParseException e) { - // Does not look like a valid expiry date - } - } - HeaderElement[] elems = null; - if (isNetscapeCookie) { - NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT; - CharArrayBuffer buffer; - ParserCursor cursor; - if (header instanceof FormattedHeader) { - buffer = ((FormattedHeader) header).getBuffer(); - cursor = new ParserCursor( - ((FormattedHeader) header).getValuePos(), - buffer.length()); - } else { - String s = header.getValue(); - if (s == null) { - throw new MalformedCookieException("Header value is null"); - } - buffer = new CharArrayBuffer(s.length()); - buffer.append(s); - cursor = new ParserCursor(0, buffer.length()); - } - elems = new HeaderElement[] { parser.parseHeader(buffer, cursor) }; - } else { - elems = header.getElements(); - } - return parse(elems, origin); - } - - public List<Header> formatCookies(final List<Cookie> cookies) { - if (cookies == null) { - throw new IllegalArgumentException("List of cookies may not be null"); - } - if (cookies.isEmpty()) { - throw new IllegalArgumentException("List of cookies may not be empty"); - } - CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size()); - buffer.append(SM.COOKIE); - buffer.append(": "); - for (int i = 0; i < cookies.size(); i++) { - Cookie cookie = cookies.get(i); - if (i > 0) { - buffer.append("; "); - } - buffer.append(cookie.getName()); - buffer.append("="); - String s = cookie.getValue(); - if (s != null) { - buffer.append(s); - } - } - List<Header> headers = new ArrayList<Header>(1); - headers.add(new BufferedHeader(buffer)); - return headers; - } - - public int getVersion() { - return 0; - } - - public Header getVersionHeader() { - return null; - } - -} diff --git a/src/org/apache/http/impl/cookie/BrowserCompatSpecFactory.java b/src/org/apache/http/impl/cookie/BrowserCompatSpecFactory.java deleted file mode 100644 index 71c0c05..0000000 --- a/src/org/apache/http/impl/cookie/BrowserCompatSpecFactory.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpecFactory.java $ - * $Revision: 576068 $ - * $Date: 2007-09-16 03:25:01 -0700 (Sun, 16 Sep 2007) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import org.apache.http.cookie.CookieSpec; -import org.apache.http.cookie.CookieSpecFactory; -import org.apache.http.cookie.params.CookieSpecPNames; -import org.apache.http.params.HttpParams; - -/** - * - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * - * @since 4.0 - */ -public class BrowserCompatSpecFactory implements CookieSpecFactory { - - public CookieSpec newInstance(final HttpParams params) { - if (params != null) { - return new BrowserCompatSpec( - (String []) params.getParameter(CookieSpecPNames.DATE_PATTERNS)); - } else { - return new BrowserCompatSpec(); - } - } - -} diff --git a/src/org/apache/http/impl/cookie/CookieSpecBase.java b/src/org/apache/http/impl/cookie/CookieSpecBase.java deleted file mode 100644 index 8e70bb1..0000000 --- a/src/org/apache/http/impl/cookie/CookieSpecBase.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/CookieSpecBase.java $ - * $Revision: 653041 $ - * $Date: 2008-05-03 03:39:28 -0700 (Sat, 03 May 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -import org.apache.http.HeaderElement; -import org.apache.http.NameValuePair; -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieAttributeHandler; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.MalformedCookieException; - -/** - * Cookie management functions shared by all specification. - * - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * - * @since 4.0 - */ -public abstract class CookieSpecBase extends AbstractCookieSpec { - - 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; - } - - protected static String getDefaultDomain(final CookieOrigin origin) { - return origin.getHost(); - } - - protected List<Cookie> parse(final HeaderElement[] elems, final CookieOrigin origin) - throws MalformedCookieException { - List<Cookie> cookies = new ArrayList<Cookie>(elems.length); - for (HeaderElement headerelement : elems) { - String name = headerelement.getName(); - String value = headerelement.getValue(); - if (name == null || name.length() == 0) { - throw new MalformedCookieException("Cookie name may not be empty"); - } - - BasicClientCookie cookie = new BasicClientCookie(name, value); - cookie.setPath(getDefaultPath(origin)); - cookie.setDomain(getDefaultDomain(origin)); - - // cycle through the parameters - NameValuePair[] attribs = headerelement.getParameters(); - for (int j = attribs.length - 1; j >= 0; j--) { - NameValuePair attrib = attribs[j]; - String s = attrib.getName().toLowerCase(Locale.ENGLISH); - - cookie.setAttribute(s, attrib.getValue()); - - CookieAttributeHandler handler = findAttribHandler(s); - if (handler != null) { - handler.parse(cookie, attrib.getValue()); - } - } - cookies.add(cookie); - } - return cookies; - } - - 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"); - } - for (CookieAttributeHandler handler: getAttribHandlers()) { - handler.validate(cookie, origin); - } - } - - 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"); - } - for (CookieAttributeHandler handler: getAttribHandlers()) { - if (!handler.match(cookie, origin)) { - return false; - } - } - return true; - } - -} diff --git a/src/org/apache/http/impl/cookie/DateParseException.java b/src/org/apache/http/impl/cookie/DateParseException.java deleted file mode 100644 index c80b669..0000000 --- a/src/org/apache/http/impl/cookie/DateParseException.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/DateParseException.java $ - * $Revision: 609105 $ - * $Date: 2008-01-05 00:55:00 -0800 (Sat, 05 Jan 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - - -/** - * An exception to indicate an error parsing a date string. - * - * @see DateUtils - * - * @author Michael Becke - */ -public class DateParseException extends Exception { - - private static final long serialVersionUID = 4417696455000643370L; - - /** - * - */ - public DateParseException() { - super(); - } - - /** - * @param message the exception message - */ - public DateParseException(String message) { - super(message); - } - -} diff --git a/src/org/apache/http/impl/cookie/DateUtils.java b/src/org/apache/http/impl/cookie/DateUtils.java deleted file mode 100644 index a0a056c..0000000 --- a/src/org/apache/http/impl/cookie/DateUtils.java +++ /dev/null @@ -1,261 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/DateUtils.java $ - * $Revision: 677240 $ - * $Date: 2008-07-16 04:25:47 -0700 (Wed, 16 Jul 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import java.lang.ref.SoftReference; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.TimeZone; - -/** - * A utility class for parsing and formatting HTTP dates as used in cookies and - * other headers. This class handles dates as defined by RFC 2616 section - * 3.3.1 as well as some other common non-standard formats. - * - * @author Christopher Brown - * @author Michael Becke - */ -public final class DateUtils { - - /** - * Date format pattern used to parse HTTP date headers in RFC 1123 format. - */ - public static final String PATTERN_RFC1123 = "EEE, dd MMM yyyy HH:mm:ss zzz"; - - /** - * Date format pattern used to parse HTTP date headers in RFC 1036 format. - */ - public static final String PATTERN_RFC1036 = "EEEE, dd-MMM-yy HH:mm:ss zzz"; - - /** - * Date format pattern used to parse HTTP date headers in ANSI C - * <code>asctime()</code> format. - */ - public static final String PATTERN_ASCTIME = "EEE MMM d HH:mm:ss yyyy"; - - private static final String[] DEFAULT_PATTERNS = new String[] { - PATTERN_RFC1036, - PATTERN_RFC1123, - PATTERN_ASCTIME - }; - - private static final Date DEFAULT_TWO_DIGIT_YEAR_START; - - public static final TimeZone GMT = TimeZone.getTimeZone("GMT"); - - static { - Calendar calendar = Calendar.getInstance(); - calendar.setTimeZone(GMT); - calendar.set(2000, Calendar.JANUARY, 1, 0, 0, 0); - calendar.set(Calendar.MILLISECOND, 0); - DEFAULT_TWO_DIGIT_YEAR_START = calendar.getTime(); - } - - /** - * Parses a date value. The formats used for parsing the date value are retrieved from - * the default http params. - * - * @param dateValue the date value to parse - * - * @return the parsed date - * - * @throws DateParseException if the value could not be parsed using any of the - * supported date formats - */ - public static Date parseDate(String dateValue) throws DateParseException { - return parseDate(dateValue, null, null); - } - - /** - * Parses the date value using the given date formats. - * - * @param dateValue the date value to parse - * @param dateFormats the date formats to use - * - * @return the parsed date - * - * @throws DateParseException if none of the dataFormats could parse the dateValue - */ - public static Date parseDate(final String dateValue, String[] dateFormats) - throws DateParseException { - return parseDate(dateValue, dateFormats, null); - } - - /** - * Parses the date value using the given date formats. - * - * @param dateValue the date value to parse - * @param dateFormats the date formats to use - * @param startDate During parsing, two digit years will be placed in the range - * <code>startDate</code> to <code>startDate + 100 years</code>. This value may - * be <code>null</code>. When <code>null</code> is given as a parameter, year - * <code>2000</code> will be used. - * - * @return the parsed date - * - * @throws DateParseException if none of the dataFormats could parse the dateValue - */ - public static Date parseDate( - String dateValue, - String[] dateFormats, - Date startDate - ) throws DateParseException { - - if (dateValue == null) { - throw new IllegalArgumentException("dateValue is null"); - } - if (dateFormats == null) { - dateFormats = DEFAULT_PATTERNS; - } - if (startDate == null) { - startDate = DEFAULT_TWO_DIGIT_YEAR_START; - } - // trim single quotes around date if present - // see issue #5279 - if (dateValue.length() > 1 - && dateValue.startsWith("'") - && dateValue.endsWith("'") - ) { - dateValue = dateValue.substring (1, dateValue.length() - 1); - } - - for (String dateFormat : dateFormats) { - SimpleDateFormat dateParser = DateFormatHolder.formatFor(dateFormat); - dateParser.set2DigitYearStart(startDate); - - try { - return dateParser.parse(dateValue); - } catch (ParseException pe) { - // ignore this exception, we will try the next format - } - } - - // we were unable to parse the date - throw new DateParseException("Unable to parse the date " + dateValue); - } - - /** - * Formats the given date according to the RFC 1123 pattern. - * - * @param date The date to format. - * @return An RFC 1123 formatted date string. - * - * @see #PATTERN_RFC1123 - */ - public static String formatDate(Date date) { - return formatDate(date, PATTERN_RFC1123); - } - - /** - * Formats the given date according to the specified pattern. The pattern - * must conform to that used by the {@link SimpleDateFormat simple date - * format} class. - * - * @param date The date to format. - * @param pattern The pattern to use for formatting the date. - * @return A formatted date string. - * - * @throws IllegalArgumentException If the given date pattern is invalid. - * - * @see SimpleDateFormat - */ - public static String formatDate(Date date, String pattern) { - if (date == null) throw new IllegalArgumentException("date is null"); - if (pattern == null) throw new IllegalArgumentException("pattern is null"); - - SimpleDateFormat formatter = DateFormatHolder.formatFor(pattern); - return formatter.format(date); - } - - /** This class should not be instantiated. */ - private DateUtils() { - } - - /** - * A factory for {@link SimpleDateFormat}s. The instances are stored in a - * threadlocal way because SimpleDateFormat is not threadsafe as noted in - * {@link SimpleDateFormat its javadoc}. - * - * @author Daniel Mueller - */ - final static class DateFormatHolder { - - private static final ThreadLocal<SoftReference<Map<String, SimpleDateFormat>>> - THREADLOCAL_FORMATS = new ThreadLocal<SoftReference<Map<String, SimpleDateFormat>>>() { - - @Override - protected SoftReference<Map<String, SimpleDateFormat>> initialValue() { - return new SoftReference<Map<String, SimpleDateFormat>>( - new HashMap<String, SimpleDateFormat>()); - } - - }; - - /** - * creates a {@link SimpleDateFormat} for the requested format string. - * - * @param pattern - * a non-<code>null</code> format String according to - * {@link SimpleDateFormat}. The format is not checked against - * <code>null</code> since all paths go through - * {@link DateUtils}. - * @return the requested format. This simple dateformat should not be used - * to {@link SimpleDateFormat#applyPattern(String) apply} to a - * different pattern. - */ - public static SimpleDateFormat formatFor(String pattern) { - SoftReference<Map<String, SimpleDateFormat>> ref = THREADLOCAL_FORMATS.get(); - Map<String, SimpleDateFormat> formats = ref.get(); - if (formats == null) { - formats = new HashMap<String, SimpleDateFormat>(); - THREADLOCAL_FORMATS.set( - new SoftReference<Map<String, SimpleDateFormat>>(formats)); - } - - SimpleDateFormat format = formats.get(pattern); - if (format == null) { - format = new SimpleDateFormat(pattern, Locale.US); - format.setTimeZone(TimeZone.getTimeZone("GMT")); - formats.put(pattern, format); - } - - return format; - } - - } - -} diff --git a/src/org/apache/http/impl/cookie/NetscapeDomainHandler.java b/src/org/apache/http/impl/cookie/NetscapeDomainHandler.java deleted file mode 100644 index 8b785ae..0000000 --- a/src/org/apache/http/impl/cookie/NetscapeDomainHandler.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDomainHandler.java $ - * $Revision: 653041 $ - * $Date: 2008-05-03 03:39:28 -0700 (Sat, 03 May 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ -package org.apache.http.impl.cookie; - -import java.util.Locale; -import java.util.StringTokenizer; - -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.MalformedCookieException; - -public class NetscapeDomainHandler extends BasicDomainHandler { - - public NetscapeDomainHandler() { - super(); - } - - @Override - public void validate(final Cookie cookie, final CookieOrigin origin) - throws MalformedCookieException { - super.validate(cookie, origin); - // Perform Netscape Cookie draft specific validation - String host = origin.getHost(); - String domain = cookie.getDomain(); - if (host.contains(".")) { - int domainParts = new StringTokenizer(domain, ".").countTokens(); - - if (isSpecialDomain(domain)) { - if (domainParts < 2) { - throw new MalformedCookieException("Domain attribute \"" - + domain - + "\" violates the Netscape cookie specification for " - + "special domains"); - } - } else { - if (domainParts < 3) { - throw new MalformedCookieException("Domain attribute \"" - + domain - + "\" violates the Netscape cookie specification"); - } - } - } - } - - /** - * Checks if the given domain is in one of the seven special - * top level domains defined by the Netscape cookie specification. - * @param domain The domain. - * @return True if the specified domain is "special" - */ - private static boolean isSpecialDomain(final String domain) { - final String ucDomain = domain.toUpperCase(Locale.ENGLISH); - return ucDomain.endsWith(".COM") - || ucDomain.endsWith(".EDU") - || ucDomain.endsWith(".NET") - || ucDomain.endsWith(".GOV") - || ucDomain.endsWith(".MIL") - || ucDomain.endsWith(".ORG") - || ucDomain.endsWith(".INT"); - } - - @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); - } - -} diff --git a/src/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java b/src/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java deleted file mode 100644 index ca6b7fa..0000000 --- a/src/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java $ - * $Revision: 603563 $ - * $Date: 2007-12-12 03:17:55 -0800 (Wed, 12 Dec 2007) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.http.HeaderElement; -import org.apache.http.NameValuePair; -import org.apache.http.ParseException; -import org.apache.http.message.BasicHeaderElement; -import org.apache.http.message.BasicHeaderValueParser; -import org.apache.http.message.ParserCursor; -import org.apache.http.util.CharArrayBuffer; - -public class NetscapeDraftHeaderParser { - - public final static NetscapeDraftHeaderParser DEFAULT = new NetscapeDraftHeaderParser(); - - private final static char[] DELIMITERS = new char[] { ';' }; - - private final BasicHeaderValueParser nvpParser; - - public NetscapeDraftHeaderParser() { - super(); - this.nvpParser = BasicHeaderValueParser.DEFAULT; - } - - public HeaderElement parseHeader( - final CharArrayBuffer buffer, - final ParserCursor cursor) throws ParseException { - if (buffer == null) { - throw new IllegalArgumentException("Char array buffer may not be null"); - } - if (cursor == null) { - throw new IllegalArgumentException("Parser cursor may not be null"); - } - NameValuePair nvp = this.nvpParser.parseNameValuePair(buffer, cursor, DELIMITERS); - List<NameValuePair> params = new ArrayList<NameValuePair>(); - while (!cursor.atEnd()) { - NameValuePair param = this.nvpParser.parseNameValuePair(buffer, cursor, DELIMITERS); - params.add(param); - } - return new BasicHeaderElement( - nvp.getName(), - nvp.getValue(), params.toArray(new NameValuePair[params.size()])); - } - -} diff --git a/src/org/apache/http/impl/cookie/NetscapeDraftSpec.java b/src/org/apache/http/impl/cookie/NetscapeDraftSpec.java deleted file mode 100644 index 3bc4f9f..0000000 --- a/src/org/apache/http/impl/cookie/NetscapeDraftSpec.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java $ - * $Revision: 677240 $ - * $Date: 2008-07-16 04:25:47 -0700 (Wed, 16 Jul 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.http.FormattedHeader; -import org.apache.http.Header; -import org.apache.http.HeaderElement; -import org.apache.http.cookie.ClientCookie; -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SM; -import org.apache.http.message.BufferedHeader; -import org.apache.http.message.ParserCursor; -import org.apache.http.util.CharArrayBuffer; - -/** - * Netscape cookie draft compliant cookie policy - * - * @author B.C. Holmes - * @author <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a> - * @author <a href="mailto:dsale@us.britannica.com">Doug Sale</a> - * @author Rod Waldhoff - * @author dIon Gillard - * @author Sean C. Sullivan - * @author <a href="mailto:JEvans@Cyveillance.com">John Evans</a> - * @author Marc A. Saegesser - * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a> - * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a> - * - * @since 4.0 - */ -public class NetscapeDraftSpec extends CookieSpecBase { - - protected static final String EXPIRES_PATTERN = "EEE, dd-MMM-yyyy HH:mm:ss z"; - - private final String[] datepatterns; - - /** Default constructor */ - public NetscapeDraftSpec(final String[] datepatterns) { - super(); - if (datepatterns != null) { - this.datepatterns = datepatterns.clone(); - } else { - this.datepatterns = new String[] { EXPIRES_PATTERN }; - } - registerAttribHandler(ClientCookie.PATH_ATTR, new BasicPathHandler()); - registerAttribHandler(ClientCookie.DOMAIN_ATTR, new NetscapeDomainHandler()); - registerAttribHandler(ClientCookie.MAX_AGE_ATTR, new BasicMaxAgeHandler()); - registerAttribHandler(ClientCookie.SECURE_ATTR, new BasicSecureHandler()); - registerAttribHandler(ClientCookie.COMMENT_ATTR, new BasicCommentHandler()); - registerAttribHandler(ClientCookie.EXPIRES_ATTR, new BasicExpiresHandler( - this.datepatterns)); - } - - /** Default constructor */ - public NetscapeDraftSpec() { - this(null); - } - - /** - * Parses the Set-Cookie value into an array of <tt>Cookie</tt>s. - * - * <p>Syntax of the Set-Cookie HTTP Response Header:</p> - * - * <p>This is the format a CGI script would use to add to - * the HTTP headers a new piece of data which is to be stored by - * the client for later retrieval.</p> - * - * <PRE> - * Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME; secure - * </PRE> - * - * <p>Please note that Netscape draft specification does not fully - * conform to the HTTP header format. Netscape draft does not specify - * whether multiple cookies may be sent in one header. Hence, comma - * character may be present in unquoted cookie value or unquoted - * parameter value.</p> - * - * @see <a href="http://wp.netscape.com/newsref/std/cookie_spec.html"> - * The Cookie Spec.</a> - * - * @param header the <tt>Set-Cookie</tt> received from the server - * @return an array of <tt>Cookie</tt>s parsed from the Set-Cookie value - * @throws MalformedCookieException if an exception occurs during parsing - */ - public List<Cookie> parse(final Header header, final CookieOrigin origin) - throws MalformedCookieException { - if (header == null) { - throw new IllegalArgumentException("Header may not be null"); - } - if (origin == null) { - throw new IllegalArgumentException("Cookie origin may not be null"); - } - NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT; - CharArrayBuffer buffer; - ParserCursor cursor; - if (header instanceof FormattedHeader) { - buffer = ((FormattedHeader) header).getBuffer(); - cursor = new ParserCursor( - ((FormattedHeader) header).getValuePos(), - buffer.length()); - } else { - String s = header.getValue(); - if (s == null) { - throw new MalformedCookieException("Header value is null"); - } - buffer = new CharArrayBuffer(s.length()); - buffer.append(s); - cursor = new ParserCursor(0, buffer.length()); - } - return parse(new HeaderElement[] { parser.parseHeader(buffer, cursor) }, origin); - } - - public List<Header> formatCookies(final List<Cookie> cookies) { - if (cookies == null) { - throw new IllegalArgumentException("List of cookies may not be null"); - } - if (cookies.isEmpty()) { - throw new IllegalArgumentException("List of cookies may not be empty"); - } - CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size()); - buffer.append(SM.COOKIE); - buffer.append(": "); - for (int i = 0; i < cookies.size(); i++) { - Cookie cookie = cookies.get(i); - if (i > 0) { - buffer.append("; "); - } - buffer.append(cookie.getName()); - String s = cookie.getValue(); - if (s != null) { - buffer.append("="); - buffer.append(s); - } - } - List<Header> headers = new ArrayList<Header>(1); - headers.add(new BufferedHeader(buffer)); - return headers; - } - - public int getVersion() { - return 0; - } - - public Header getVersionHeader() { - return null; - } - -} diff --git a/src/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java b/src/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java deleted file mode 100644 index 0dcb187..0000000 --- a/src/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java $ - * $Revision: 657334 $ - * $Date: 2008-05-17 04:44:16 -0700 (Sat, 17 May 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import org.apache.http.cookie.CookieSpec; -import org.apache.http.cookie.CookieSpecFactory; -import org.apache.http.cookie.params.CookieSpecPNames; -import org.apache.http.params.HttpParams; - -/** - * - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * - * @since 4.0 - */ -public class NetscapeDraftSpecFactory implements CookieSpecFactory { - - public CookieSpec newInstance(final HttpParams params) { - if (params != null) { - return new NetscapeDraftSpec( - (String []) params.getParameter(CookieSpecPNames.DATE_PATTERNS)); - } else { - return new NetscapeDraftSpec(); - } - } - -} diff --git a/src/org/apache/http/impl/cookie/RFC2109DomainHandler.java b/src/org/apache/http/impl/cookie/RFC2109DomainHandler.java deleted file mode 100644 index 9cfd484..0000000 --- a/src/org/apache/http/impl/cookie/RFC2109DomainHandler.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109DomainHandler.java $ - * $Revision: 653041 $ - * $Date: 2008-05-03 03:39:28 -0700 (Sat, 03 May 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ -package org.apache.http.impl.cookie; - -import java.util.Locale; - -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieAttributeHandler; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SetCookie; - -public class RFC2109DomainHandler implements CookieAttributeHandler { - - public RFC2109DomainHandler() { - super(); - } - - public void parse(final SetCookie cookie, final String value) - throws MalformedCookieException { - if (cookie == null) { - throw new IllegalArgumentException("Cookie may not be null"); - } - if (value == null) { - throw new MalformedCookieException("Missing value for domain attribute"); - } - if (value.trim().length() == 0) { - throw new MalformedCookieException("Blank value for domain attribute"); - } - cookie.setDomain(value); - } - - 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 host = origin.getHost(); - String domain = cookie.getDomain(); - if (domain == null) { - throw new MalformedCookieException("Cookie domain may not be null"); - } - if (!domain.equals(host)) { - int dotIndex = domain.indexOf('.'); - if (dotIndex == -1) { - throw new MalformedCookieException("Domain attribute \"" - + domain - + "\" does not match the host \"" - + host + "\""); - } - // domain must start with dot - if (!domain.startsWith(".")) { - throw new MalformedCookieException("Domain attribute \"" - + domain - + "\" violates RFC 2109: domain must start with a dot"); - } - // domain must have at least one embedded dot - dotIndex = domain.indexOf('.', 1); - if (dotIndex < 0 || dotIndex == domain.length() - 1) { - throw new MalformedCookieException("Domain attribute \"" - + domain - + "\" violates RFC 2109: domain must contain an embedded dot"); - } - host = host.toLowerCase(Locale.ENGLISH); - if (!host.endsWith(domain)) { - throw new MalformedCookieException( - "Illegal domain attribute \"" + domain - + "\". Domain of origin: \"" + host + "\""); - } - // host minus domain may not contain any dots - String hostWithoutDomain = host.substring(0, host.length() - domain.length()); - if (hostWithoutDomain.indexOf('.') != -1) { - throw new MalformedCookieException("Domain attribute \"" - + domain - + "\" violates RFC 2109: host minus domain may not contain any dots"); - } - } - } - - 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 host = origin.getHost(); - String domain = cookie.getDomain(); - if (domain == null) { - return false; - } - return host.equals(domain) || (domain.startsWith(".") && host.endsWith(domain)); - } - -} diff --git a/src/org/apache/http/impl/cookie/RFC2109Spec.java b/src/org/apache/http/impl/cookie/RFC2109Spec.java deleted file mode 100644 index 9e45408..0000000 --- a/src/org/apache/http/impl/cookie/RFC2109Spec.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java $ - * $Revision: 677240 $ - * $Date: 2008-07-16 04:25:47 -0700 (Wed, 16 Jul 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.apache.http.Header; -import org.apache.http.HeaderElement; -import org.apache.http.cookie.ClientCookie; -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.CookiePathComparator; -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SM; -import org.apache.http.message.BufferedHeader; -import org.apache.http.util.CharArrayBuffer; - -/** - * RFC 2109 compliant cookie policy - * - * @author B.C. Holmes - * @author <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a> - * @author <a href="mailto:dsale@us.britannica.com">Doug Sale</a> - * @author Rod Waldhoff - * @author dIon Gillard - * @author Sean C. Sullivan - * @author <a href="mailto:JEvans@Cyveillance.com">John Evans</a> - * @author Marc A. Saegesser - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a> - * - * @since 4.0 - */ - -public class RFC2109Spec extends CookieSpecBase { - - private final static CookiePathComparator PATH_COMPARATOR = new CookiePathComparator(); - - private final static String[] DATE_PATTERNS = { - DateUtils.PATTERN_RFC1123, - DateUtils.PATTERN_RFC1036, - DateUtils.PATTERN_ASCTIME - }; - - private final String[] datepatterns; - private final boolean oneHeader; - - /** Default constructor */ - public RFC2109Spec(final String[] datepatterns, boolean oneHeader) { - super(); - if (datepatterns != null) { - this.datepatterns = datepatterns.clone(); - } else { - this.datepatterns = DATE_PATTERNS; - } - this.oneHeader = oneHeader; - registerAttribHandler(ClientCookie.VERSION_ATTR, new RFC2109VersionHandler()); - registerAttribHandler(ClientCookie.PATH_ATTR, new BasicPathHandler()); - registerAttribHandler(ClientCookie.DOMAIN_ATTR, new RFC2109DomainHandler()); - registerAttribHandler(ClientCookie.MAX_AGE_ATTR, new BasicMaxAgeHandler()); - registerAttribHandler(ClientCookie.SECURE_ATTR, new BasicSecureHandler()); - registerAttribHandler(ClientCookie.COMMENT_ATTR, new BasicCommentHandler()); - registerAttribHandler(ClientCookie.EXPIRES_ATTR, new BasicExpiresHandler( - this.datepatterns)); - } - - /** Default constructor */ - public RFC2109Spec() { - this(null, false); - } - - public List<Cookie> parse(final Header header, final CookieOrigin origin) - throws MalformedCookieException { - if (header == null) { - throw new IllegalArgumentException("Header may not be null"); - } - if (origin == null) { - throw new IllegalArgumentException("Cookie origin may not be null"); - } - HeaderElement[] elems = header.getElements(); - return parse(elems, origin); - } - - @Override - public void validate(final Cookie cookie, final CookieOrigin origin) - throws MalformedCookieException { - if (cookie == null) { - throw new IllegalArgumentException("Cookie may not be null"); - } - String name = cookie.getName(); - if (name.indexOf(' ') != -1) { - throw new MalformedCookieException("Cookie name may not contain blanks"); - } - if (name.startsWith("$")) { - throw new MalformedCookieException("Cookie name may not start with $"); - } - super.validate(cookie, origin); - } - - public List<Header> formatCookies(List<Cookie> cookies) { - if (cookies == null) { - throw new IllegalArgumentException("List of cookies may not be null"); - } - if (cookies.isEmpty()) { - throw new IllegalArgumentException("List of cookies may not be empty"); - } - if (cookies.size() > 1) { - // Create a mutable copy and sort the copy. - cookies = new ArrayList<Cookie>(cookies); - Collections.sort(cookies, PATH_COMPARATOR); - } - if (this.oneHeader) { - return doFormatOneHeader(cookies); - } else { - return doFormatManyHeaders(cookies); - } - } - - private List<Header> doFormatOneHeader(final List<Cookie> cookies) { - int version = Integer.MAX_VALUE; - // Pick the lowest common denominator - for (Cookie cookie : cookies) { - if (cookie.getVersion() < version) { - version = cookie.getVersion(); - } - } - CharArrayBuffer buffer = new CharArrayBuffer(40 * cookies.size()); - buffer.append(SM.COOKIE); - buffer.append(": "); - buffer.append("$Version="); - buffer.append(Integer.toString(version)); - for (Cookie cooky : cookies) { - buffer.append("; "); - Cookie cookie = cooky; - formatCookieAsVer(buffer, cookie, version); - } - List<Header> headers = new ArrayList<Header>(1); - headers.add(new BufferedHeader(buffer)); - return headers; - } - - private List<Header> doFormatManyHeaders(final List<Cookie> cookies) { - List<Header> headers = new ArrayList<Header>(cookies.size()); - for (Cookie cookie : cookies) { - int version = cookie.getVersion(); - CharArrayBuffer buffer = new CharArrayBuffer(40); - buffer.append("Cookie: "); - buffer.append("$Version="); - buffer.append(Integer.toString(version)); - buffer.append("; "); - formatCookieAsVer(buffer, cookie, version); - headers.add(new BufferedHeader(buffer)); - } - return headers; - } - - /** - * Return a name/value 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 name The cookie name - * @param value The cookie value - * @param version The cookie version - */ - protected void formatParamAsVer(final CharArrayBuffer buffer, - final String name, final String value, int version) { - buffer.append(name); - buffer.append("="); - if (value != null) { - if (version > 0) { - buffer.append('\"'); - buffer.append(value); - buffer.append('\"'); - } else { - buffer.append(value); - } - } - } - - /** - * 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); - } - } - } - - public int getVersion() { - return 1; - } - - public Header getVersionHeader() { - return null; - } - -} diff --git a/src/org/apache/http/impl/cookie/RFC2109SpecFactory.java b/src/org/apache/http/impl/cookie/RFC2109SpecFactory.java deleted file mode 100644 index 35c506e..0000000 --- a/src/org/apache/http/impl/cookie/RFC2109SpecFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109SpecFactory.java $ - * $Revision: 576068 $ - * $Date: 2007-09-16 03:25:01 -0700 (Sun, 16 Sep 2007) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import org.apache.http.cookie.CookieSpec; -import org.apache.http.cookie.CookieSpecFactory; -import org.apache.http.cookie.params.CookieSpecPNames; -import org.apache.http.params.HttpParams; - -/** - * - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * - * @since 4.0 - */ -public class RFC2109SpecFactory implements CookieSpecFactory { - - public CookieSpec newInstance(final HttpParams params) { - if (params != null) { - return new RFC2109Spec( - (String []) params.getParameter(CookieSpecPNames.DATE_PATTERNS), - params.getBooleanParameter(CookieSpecPNames.SINGLE_COOKIE_HEADER, false)); - } else { - return new RFC2109Spec(); - } - } - -} diff --git a/src/org/apache/http/impl/cookie/RFC2109VersionHandler.java b/src/org/apache/http/impl/cookie/RFC2109VersionHandler.java deleted file mode 100644 index d2c4955..0000000 --- a/src/org/apache/http/impl/cookie/RFC2109VersionHandler.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109VersionHandler.java $ - * $Revision: 653041 $ - * $Date: 2008-05-03 03:39:28 -0700 (Sat, 03 May 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ -package org.apache.http.impl.cookie; - -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SetCookie; - -public class RFC2109VersionHandler extends AbstractCookieAttributeHandler { - - public RFC2109VersionHandler() { - super(); - } - - public void parse(final SetCookie cookie, final String value) - throws MalformedCookieException { - if (cookie == null) { - throw new IllegalArgumentException("Cookie may not be null"); - } - if (value == null) { - throw new MalformedCookieException("Missing value for version attribute"); - } - if (value.trim().length() == 0) { - throw new MalformedCookieException("Blank value for version attribute"); - } - try { - cookie.setVersion(Integer.parseInt(value)); - } catch (NumberFormatException e) { - throw new MalformedCookieException("Invalid version: " - + e.getMessage()); - } - } - - @Override - public void validate(final Cookie cookie, final CookieOrigin origin) - throws MalformedCookieException { - if (cookie == null) { - throw new IllegalArgumentException("Cookie may not be null"); - } - if (cookie.getVersion() < 0) { - throw new MalformedCookieException("Cookie version may not be negative"); - } - } - -} diff --git a/src/org/apache/http/impl/cookie/RFC2965CommentUrlAttributeHandler.java b/src/org/apache/http/impl/cookie/RFC2965CommentUrlAttributeHandler.java deleted file mode 100644 index aa3a1c5..0000000 --- a/src/org/apache/http/impl/cookie/RFC2965CommentUrlAttributeHandler.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965CommentUrlAttributeHandler.java $ - * $Revision: 590695 $ - * $Date: 2007-10-31 07:55:41 -0700 (Wed, 31 Oct 2007) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieAttributeHandler; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SetCookie; -import org.apache.http.cookie.SetCookie2; - -/** - * <tt>"CommantURL"</tt> cookie attribute handler for RFC 2965 cookie spec. - */ - public class RFC2965CommentUrlAttributeHandler implements CookieAttributeHandler { - - public RFC2965CommentUrlAttributeHandler() { - super(); - } - - public void parse(final SetCookie cookie, final String commenturl) - throws MalformedCookieException { - if (cookie instanceof SetCookie2) { - SetCookie2 cookie2 = (SetCookie2) cookie; - cookie2.setCommentURL(commenturl); - } - } - - public void validate(final Cookie cookie, final CookieOrigin origin) - throws MalformedCookieException { - } - - public boolean match(final Cookie cookie, final CookieOrigin origin) { - return true; - } - - }
\ No newline at end of file diff --git a/src/org/apache/http/impl/cookie/RFC2965DiscardAttributeHandler.java b/src/org/apache/http/impl/cookie/RFC2965DiscardAttributeHandler.java deleted file mode 100644 index aa81145..0000000 --- a/src/org/apache/http/impl/cookie/RFC2965DiscardAttributeHandler.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965DiscardAttributeHandler.java $ - * $Revision: 590695 $ - * $Date: 2007-10-31 07:55:41 -0700 (Wed, 31 Oct 2007) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieAttributeHandler; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SetCookie; -import org.apache.http.cookie.SetCookie2; - -/** - * <tt>"Discard"</tt> cookie attribute handler for RFC 2965 cookie spec. - */ - public class RFC2965DiscardAttributeHandler implements CookieAttributeHandler { - - public RFC2965DiscardAttributeHandler() { - super(); - } - - public void parse(final SetCookie cookie, final String commenturl) - throws MalformedCookieException { - if (cookie instanceof SetCookie2) { - SetCookie2 cookie2 = (SetCookie2) cookie; - cookie2.setDiscard(true); - } - } - - public void validate(final Cookie cookie, final CookieOrigin origin) - throws MalformedCookieException { - } - - public boolean match(final Cookie cookie, final CookieOrigin origin) { - return true; - } - - }
\ No newline at end of file diff --git a/src/org/apache/http/impl/cookie/RFC2965DomainAttributeHandler.java b/src/org/apache/http/impl/cookie/RFC2965DomainAttributeHandler.java deleted file mode 100644 index b07e5e9..0000000 --- a/src/org/apache/http/impl/cookie/RFC2965DomainAttributeHandler.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965DomainAttributeHandler.java $ - * $Revision: 653041 $ - * $Date: 2008-05-03 03:39:28 -0700 (Sat, 03 May 2008) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import java.util.Locale; - -import org.apache.http.cookie.ClientCookie; -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieAttributeHandler; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SetCookie; - -/** - * <tt>"Domain"</tt> cookie attribute handler for RFC 2965 cookie spec. - * - * @author jain.samit@gmail.com (Samit Jain) - * - * @since 3.1 - */ -public class RFC2965DomainAttributeHandler implements CookieAttributeHandler { - - public RFC2965DomainAttributeHandler() { - super(); - } - - /** - * Parse cookie domain attribute. - */ - public void parse(final SetCookie cookie, String domain) - throws MalformedCookieException { - if (cookie == null) { - throw new IllegalArgumentException("Cookie may not be null"); - } - if (domain == null) { - throw new MalformedCookieException( - "Missing value for domain attribute"); - } - if (domain.trim().length() == 0) { - throw new MalformedCookieException( - "Blank value for domain attribute"); - } - domain = domain.toLowerCase(Locale.ENGLISH); - if (!domain.startsWith(".")) { - // Per RFC 2965 section 3.2.2 - // "... If an explicitly specified value does not start with - // a dot, the user agent supplies a leading dot ..." - // That effectively implies that the domain attribute - // MAY NOT be an IP address of a host name - domain = '.' + domain; - } - cookie.setDomain(domain); - } - - /** - * Performs domain-match as defined by the RFC2965. - * <p> - * Host A's name domain-matches host B's if - * <ol> - * <ul>their host name strings string-compare equal; or</ul> - * <ul>A is a HDN string and has the form NB, where N is a non-empty - * name string, B has the form .B', and B' is a HDN string. (So, - * x.y.com domain-matches .Y.com but not Y.com.)</ul> - * </ol> - * - * @param host host name where cookie is received from or being sent to. - * @param domain The cookie domain attribute. - * @return true if the specified host matches the given domain. - */ - public boolean domainMatch(String host, String domain) { - boolean match = host.equals(domain) - || (domain.startsWith(".") && host.endsWith(domain)); - - return match; - } - - /** - * Validate cookie domain attribute. - */ - 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 host = origin.getHost().toLowerCase(Locale.ENGLISH); - if (cookie.getDomain() == null) { - throw new MalformedCookieException("Invalid cookie state: " + - "domain not specified"); - } - String cookieDomain = cookie.getDomain().toLowerCase(Locale.ENGLISH); - - if (cookie instanceof ClientCookie - && ((ClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)) { - // Domain attribute must start with a dot - if (!cookieDomain.startsWith(".")) { - throw new MalformedCookieException("Domain attribute \"" + - cookie.getDomain() + "\" violates RFC 2109: domain must start with a dot"); - } - - // Domain attribute must contain at least one embedded dot, - // or the value must be equal to .local. - int dotIndex = cookieDomain.indexOf('.', 1); - if (((dotIndex < 0) || (dotIndex == cookieDomain.length() - 1)) - && (!cookieDomain.equals(".local"))) { - throw new MalformedCookieException( - "Domain attribute \"" + cookie.getDomain() - + "\" violates RFC 2965: the value contains no embedded dots " - + "and the value is not .local"); - } - - // The effective host name must domain-match domain attribute. - if (!domainMatch(host, cookieDomain)) { - throw new MalformedCookieException( - "Domain attribute \"" + cookie.getDomain() - + "\" violates RFC 2965: effective host name does not " - + "domain-match domain attribute."); - } - - // effective host name minus domain must not contain any dots - String effectiveHostWithoutDomain = host.substring( - 0, host.length() - cookieDomain.length()); - if (effectiveHostWithoutDomain.indexOf('.') != -1) { - throw new MalformedCookieException("Domain attribute \"" - + cookie.getDomain() + "\" violates RFC 2965: " - + "effective host minus domain may not contain any dots"); - } - } else { - // Domain was not specified in header. In this case, domain must - // string match request host (case-insensitive). - if (!cookie.getDomain().equals(host)) { - throw new MalformedCookieException("Illegal domain attribute: \"" - + cookie.getDomain() + "\"." - + "Domain of origin: \"" - + host + "\""); - } - } - } - - /** - * Match cookie domain attribute. - */ - 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 host = origin.getHost().toLowerCase(Locale.ENGLISH); - String cookieDomain = cookie.getDomain(); - - // The effective host name MUST domain-match the Domain - // attribute of the cookie. - if (!domainMatch(host, cookieDomain)) { - return false; - } - // effective host name minus domain must not contain any dots - String effectiveHostWithoutDomain = host.substring( - 0, host.length() - cookieDomain.length()); - return effectiveHostWithoutDomain.indexOf('.') == -1; - } - -}
\ No newline at end of file diff --git a/src/org/apache/http/impl/cookie/RFC2965PortAttributeHandler.java b/src/org/apache/http/impl/cookie/RFC2965PortAttributeHandler.java deleted file mode 100644 index b881cda..0000000 --- a/src/org/apache/http/impl/cookie/RFC2965PortAttributeHandler.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965PortAttributeHandler.java $ - * $Revision: 590695 $ - * $Date: 2007-10-31 07:55:41 -0700 (Wed, 31 Oct 2007) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import java.util.StringTokenizer; - -import org.apache.http.cookie.ClientCookie; -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieAttributeHandler; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SetCookie; -import org.apache.http.cookie.SetCookie2; - -/** - * <tt>"Port"</tt> cookie attribute handler for RFC 2965 cookie spec. - */ -public class RFC2965PortAttributeHandler implements CookieAttributeHandler { - - public RFC2965PortAttributeHandler() { - super(); - } - - /** - * Parses the given Port attribute value (e.g. "8000,8001,8002") - * into an array of ports. - * - * @param portValue port attribute value - * @return parsed array of ports - * @throws MalformedCookieException if there is a problem in - * parsing due to invalid portValue. - */ - private static int[] parsePortAttribute(final String portValue) - throws MalformedCookieException { - StringTokenizer st = new StringTokenizer(portValue, ","); - int[] ports = new int[st.countTokens()]; - try { - int i = 0; - while(st.hasMoreTokens()) { - ports[i] = Integer.parseInt(st.nextToken().trim()); - if (ports[i] < 0) { - throw new MalformedCookieException ("Invalid Port attribute."); - } - ++i; - } - } catch (NumberFormatException e) { - throw new MalformedCookieException ("Invalid Port " - + "attribute: " + e.getMessage()); - } - return ports; - } - - /** - * Returns <tt>true</tt> if the given port exists in the given - * ports list. - * - * @param port port of host where cookie was received from or being sent to. - * @param ports port list - * @return true returns <tt>true</tt> if the given port exists in - * the given ports list; <tt>false</tt> otherwise. - */ - private static boolean portMatch(int port, int[] ports) { - boolean portInList = false; - for (int i = 0, len = ports.length; i < len; i++) { - if (port == ports[i]) { - portInList = true; - break; - } - } - return portInList; - } - - /** - * Parse cookie port attribute. - */ - public void parse(final SetCookie cookie, final String portValue) - throws MalformedCookieException { - if (cookie == null) { - throw new IllegalArgumentException("Cookie may not be null"); - } - if (cookie instanceof SetCookie2) { - SetCookie2 cookie2 = (SetCookie2) cookie; - if (portValue != null && portValue.trim().length() > 0) { - int[] ports = parsePortAttribute(portValue); - cookie2.setPorts(ports); - } - } - } - - /** - * 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."); - } - } - } - - /** - * 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; - } - -} diff --git a/src/org/apache/http/impl/cookie/RFC2965Spec.java b/src/org/apache/http/impl/cookie/RFC2965Spec.java deleted file mode 100644 index 9422fdf..0000000 --- a/src/org/apache/http/impl/cookie/RFC2965Spec.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java $ - * $Revision: 653041 $ - * $Date: 2008-05-03 03:39:28 -0700 (Sat, 03 May 2008) $ - * - * ==================================================================== - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import org.apache.http.Header; -import org.apache.http.HeaderElement; -import org.apache.http.NameValuePair; -import org.apache.http.cookie.ClientCookie; -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieAttributeHandler; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SM; -import org.apache.http.message.BufferedHeader; -import org.apache.http.util.CharArrayBuffer; - -/** - * <p>RFC 2965 specific cookie management functions.</p> - * - * @author jain.samit@gmail.com (Samit Jain) - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * - * @since 3.1 - */ -public class RFC2965Spec extends RFC2109Spec { - - /** - * Default constructor - * - */ - public RFC2965Spec() { - this(null, false); - } - - public RFC2965Spec(final String[] datepatterns, boolean oneHeader) { - super(datepatterns, oneHeader); - registerAttribHandler(ClientCookie.DOMAIN_ATTR, new RFC2965DomainAttributeHandler()); - registerAttribHandler(ClientCookie.PORT_ATTR, new RFC2965PortAttributeHandler()); - registerAttribHandler(ClientCookie.COMMENTURL_ATTR, new RFC2965CommentUrlAttributeHandler()); - registerAttribHandler(ClientCookie.DISCARD_ATTR, new RFC2965DiscardAttributeHandler()); - registerAttribHandler(ClientCookie.VERSION_ATTR, new RFC2965VersionAttributeHandler()); - } - - private BasicClientCookie createCookie( - final String name, final String value, final CookieOrigin origin) { - BasicClientCookie cookie = new BasicClientCookie(name, value); - cookie.setPath(getDefaultPath(origin)); - cookie.setDomain(getDefaultDomain(origin)); - return cookie; - } - - 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; - } - - @Override - public List<Cookie> parse( - final Header header, - CookieOrigin origin) throws MalformedCookieException { - if (header == null) { - throw new IllegalArgumentException("Header may not be null"); - } - if (origin == null) { - throw new IllegalArgumentException("Cookie origin may not be null"); - } - - origin = adjustEffectiveHost(origin); - - HeaderElement[] elems = header.getElements(); - - List<Cookie> cookies = new ArrayList<Cookie>(elems.length); - for (HeaderElement headerelement : elems) { - String name = headerelement.getName(); - String value = headerelement.getValue(); - if (name == null || name.length() == 0) { - throw new MalformedCookieException("Cookie name may not be empty"); - } - - BasicClientCookie cookie; - if (header.getName().equals(SM.SET_COOKIE2)) { - cookie = createCookie2(name, value, origin); - } else { - cookie = createCookie(name, value, origin); - } - - // cycle through the parameters - NameValuePair[] attribs = headerelement.getParameters(); - - // Eliminate duplicate attributes. The first occurrence takes precedence - // See RFC2965: 3.2 Origin Server Role - Map<String, NameValuePair> attribmap = - new HashMap<String, NameValuePair>(attribs.length); - for (int j = attribs.length - 1; j >= 0; j--) { - NameValuePair param = attribs[j]; - attribmap.put(param.getName().toLowerCase(Locale.ENGLISH), param); - } - for (Map.Entry<String, NameValuePair> entry : attribmap.entrySet()) { - NameValuePair attrib = entry.getValue(); - String s = attrib.getName().toLowerCase(Locale.ENGLISH); - - cookie.setAttribute(s, attrib.getValue()); - - CookieAttributeHandler handler = findAttribHandler(s); - if (handler != null) { - handler.parse(cookie, attrib.getValue()); - } - } - cookies.add(cookie); - } - return cookies; - } - - @Override - public void validate(final Cookie cookie, 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"); - } - origin = adjustEffectiveHost(origin); - super.validate(cookie, origin); - } - - @Override - public boolean match(final 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"); - } - origin = adjustEffectiveHost(origin); - return super.match(cookie, origin); - } - - /** - * 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("\""); - } - } - } - - /** - * Set 'effective host name' as defined in RFC 2965. - * <p> - * If a host name contains no dots, the effective host name is - * that name with the string .local appended to it. Otherwise - * the effective host name is the same as the host name. Note - * that all effective host names contain at least one dot. - * - * @param origin origin where cookie is received from or being sent to. - * @return - */ - private static CookieOrigin adjustEffectiveHost(final CookieOrigin origin) { - String host = origin.getHost(); - - // Test if the host name appears to be a fully qualified DNS name, - // IPv4 address or IPv6 address - boolean isLocalHost = true; - for (int i = 0; i < host.length(); i++) { - char ch = host.charAt(i); - if (ch == '.' || ch == ':') { - isLocalHost = false; - break; - } - } - if (isLocalHost) { - host += ".local"; - return new CookieOrigin( - host, - origin.getPort(), - origin.getPath(), - origin.isSecure()); - } else { - return origin; - } - } - - @Override - public int getVersion() { - return 1; - } - - @Override - public Header getVersionHeader() { - CharArrayBuffer buffer = new CharArrayBuffer(40); - buffer.append(SM.COOKIE2); - buffer.append(": "); - buffer.append("$Version="); - buffer.append(Integer.toString(getVersion())); - return new BufferedHeader(buffer); - } - -} - diff --git a/src/org/apache/http/impl/cookie/RFC2965SpecFactory.java b/src/org/apache/http/impl/cookie/RFC2965SpecFactory.java deleted file mode 100644 index 4b3cc4d..0000000 --- a/src/org/apache/http/impl/cookie/RFC2965SpecFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965SpecFactory.java $ - * $Revision: 581953 $ - * $Date: 2007-10-04 08:53:50 -0700 (Thu, 04 Oct 2007) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import org.apache.http.cookie.CookieSpec; -import org.apache.http.cookie.CookieSpecFactory; -import org.apache.http.cookie.params.CookieSpecPNames; -import org.apache.http.params.HttpParams; - -/** - * - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * - * @since 4.0 - */ -public class RFC2965SpecFactory implements CookieSpecFactory { - - public CookieSpec newInstance(final HttpParams params) { - if (params != null) { - return new RFC2965Spec( - (String []) params.getParameter(CookieSpecPNames.DATE_PATTERNS), - params.getBooleanParameter(CookieSpecPNames.SINGLE_COOKIE_HEADER, false)); - } else { - return new RFC2965Spec(); - } - } - -} diff --git a/src/org/apache/http/impl/cookie/RFC2965VersionAttributeHandler.java b/src/org/apache/http/impl/cookie/RFC2965VersionAttributeHandler.java deleted file mode 100644 index 8ea8481..0000000 --- a/src/org/apache/http/impl/cookie/RFC2965VersionAttributeHandler.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965VersionAttributeHandler.java $ - * $Revision: 590695 $ - * $Date: 2007-10-31 07:55:41 -0700 (Wed, 31 Oct 2007) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package org.apache.http.impl.cookie; - -import org.apache.http.cookie.ClientCookie; -import org.apache.http.cookie.Cookie; -import org.apache.http.cookie.CookieAttributeHandler; -import org.apache.http.cookie.CookieOrigin; -import org.apache.http.cookie.MalformedCookieException; -import org.apache.http.cookie.SetCookie; -import org.apache.http.cookie.SetCookie2; - -/** - * <tt>"Version"</tt> cookie attribute handler for RFC 2965 cookie spec. - */ -public class RFC2965VersionAttributeHandler implements CookieAttributeHandler { - - public RFC2965VersionAttributeHandler() { - super(); - } - - /** - * Parse cookie version attribute. - */ - public void parse(final SetCookie cookie, final String value) - throws MalformedCookieException { - if (cookie == null) { - throw new IllegalArgumentException("Cookie may not be null"); - } - if (value == null) { - throw new MalformedCookieException( - "Missing value for version attribute"); - } - int version = -1; - try { - version = Integer.parseInt(value); - } catch (NumberFormatException e) { - version = -1; - } - if (version < 0) { - throw new MalformedCookieException("Invalid cookie version."); - } - cookie.setVersion(version); - } - - /** - * 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."); - } - } - } - - public boolean match(final Cookie cookie, final CookieOrigin origin) { - return true; - } - -}
\ No newline at end of file diff --git a/src/org/apache/http/impl/cookie/package.html b/src/org/apache/http/impl/cookie/package.html deleted file mode 100644 index e301283..0000000 --- a/src/org/apache/http/impl/cookie/package.html +++ /dev/null @@ -1,4 +0,0 @@ -<body> - -</body> - |