From d8d769db59d9efd604931efdef986f1ebc577bda Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Sat, 22 Sep 2007 10:56:04 +0000 Subject: [PATCH] * Added Port and commentURL attributes to Cookie interface (required by RFC2965) * Added SetCookie2 interface representing the Set-Cookie2 header * Copied CookieVersionSupport interface from HttpClient 3.1 branch git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@578403 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/http/auth/params/AuthPNames.java | 4 -- .../http/conn/params/ConnRoutePNames.java | 2 - .../org/apache/http/cookie/ClientCookie.java | 5 ++ .../java/org/apache/http/cookie/Cookie.java | 12 ++++ .../http/cookie/CookieVersionSupport.java | 48 ++++++++++++++++ .../main/java/org/apache/http/cookie/SM.java | 4 +- .../org/apache/http/cookie/SetCookie2.java | 57 +++++++++++++++++++ .../http/cookie/params/CookieSpecPNames.java | 3 - .../apache/http/impl/cookie/BasicCookie.java | 18 ++++++ 9 files changed, 142 insertions(+), 11 deletions(-) create mode 100644 module-client/src/main/java/org/apache/http/cookie/CookieVersionSupport.java create mode 100644 module-client/src/main/java/org/apache/http/cookie/SetCookie2.java diff --git a/module-client/src/main/java/org/apache/http/auth/params/AuthPNames.java b/module-client/src/main/java/org/apache/http/auth/params/AuthPNames.java index 51a671249..7b6837632 100644 --- a/module-client/src/main/java/org/apache/http/auth/params/AuthPNames.java +++ b/module-client/src/main/java/org/apache/http/auth/params/AuthPNames.java @@ -31,10 +31,6 @@ package org.apache.http.auth.params; -import org.apache.http.params.HttpParams; -import org.apache.http.protocol.HTTP; - - /** * Parameter names for HttpAuth. * diff --git a/module-client/src/main/java/org/apache/http/conn/params/ConnRoutePNames.java b/module-client/src/main/java/org/apache/http/conn/params/ConnRoutePNames.java index e66b4e3c7..9d9af0d7c 100644 --- a/module-client/src/main/java/org/apache/http/conn/params/ConnRoutePNames.java +++ b/module-client/src/main/java/org/apache/http/conn/params/ConnRoutePNames.java @@ -30,8 +30,6 @@ package org.apache.http.conn.params; -import org.apache.http.params.HttpParams; - /** * Parameter names for routing in HttpConn. * diff --git a/module-client/src/main/java/org/apache/http/cookie/ClientCookie.java b/module-client/src/main/java/org/apache/http/cookie/ClientCookie.java index f8c52a0b4..fe063879e 100644 --- a/module-client/src/main/java/org/apache/http/cookie/ClientCookie.java +++ b/module-client/src/main/java/org/apache/http/cookie/ClientCookie.java @@ -55,6 +55,11 @@ public interface ClientCookie extends Cookie { public static final String COMMENT_ATTR = "comment"; public static final String EXPIRES_ATTR = "expires"; + // RFC2965 attributes + public static final String PORT_ATTR = "port"; + public static final String COMMENTURL_ATTR = "commenturl"; + public static final String DISCARD_ATTR = "discard"; + String getAttribute(String name); boolean containsAttribute(String name); diff --git a/module-client/src/main/java/org/apache/http/cookie/Cookie.java b/module-client/src/main/java/org/apache/http/cookie/Cookie.java index f2222859f..c2ec7b2a2 100644 --- a/module-client/src/main/java/org/apache/http/cookie/Cookie.java +++ b/module-client/src/main/java/org/apache/http/cookie/Cookie.java @@ -66,6 +66,12 @@ public interface Cookie { */ String getComment(); + /** + * If a user agent (web browser) presents this cookie to a user, the + * cookie's purpose will be described by the information at this URL. + */ + String getCommentURL(); + /** * Returns the expiration {@link Date} of the cookie, or null * if none exists. @@ -99,6 +105,12 @@ public interface Cookie { */ String getPath(); + /** + * Get the Port attribute. It restricts the ports to which a cookie + * may be returned in a Cookie request header. + */ + int[] getPorts(); + /** * Indicates whether this cookie requires a secure connection. * diff --git a/module-client/src/main/java/org/apache/http/cookie/CookieVersionSupport.java b/module-client/src/main/java/org/apache/http/cookie/CookieVersionSupport.java new file mode 100644 index 000000000..75d1beb0d --- /dev/null +++ b/module-client/src/main/java/org/apache/http/cookie/CookieVersionSupport.java @@ -0,0 +1,48 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * + * 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 + * . + * + */ + +package org.apache.http.cookie; + +import org.apache.http.Header; + +/** + * Defines cookie specification specific capabilities + * + * @author Oleg Kalnichevski + * + * @since 3.1 + */ +public interface CookieVersionSupport { + + int getVersion(); + + Header getVersionHeader(); + +} diff --git a/module-client/src/main/java/org/apache/http/cookie/SM.java b/module-client/src/main/java/org/apache/http/cookie/SM.java index 14a960749..a00c0ef23 100644 --- a/module-client/src/main/java/org/apache/http/cookie/SM.java +++ b/module-client/src/main/java/org/apache/http/cookie/SM.java @@ -40,8 +40,8 @@ package org.apache.http.cookie; */ public interface SM { - public static final String COOKIE= "Cookie"; - + public static final String COOKIE = "Cookie"; + public static final String COOKIE_2 = "Cookie2"; public static final String SET_COOKIE = "Set-Cookie"; } diff --git a/module-client/src/main/java/org/apache/http/cookie/SetCookie2.java b/module-client/src/main/java/org/apache/http/cookie/SetCookie2.java new file mode 100644 index 000000000..0de2a79aa --- /dev/null +++ b/module-client/src/main/java/org/apache/http/cookie/SetCookie2.java @@ -0,0 +1,57 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * 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 + * . + * + */ + +package org.apache.http.cookie; + +/** + * This interface represents a SetCookie2 response header sent by the + * origin server to the HTTP agent in order to maintain a conversational state. + * + * @author Oleg Kalnichevski + * + * @since 4.0 + */ +public interface SetCookie2 extends Cookie { + + /** + * If a user agent (web browser) presents this cookie to a user, the + * cookie's purpose will be described by the information at this URL. + */ + void setCommentURL(String commentURL); + + /** + * Sets the Port attribute. It restricts the ports to which a cookie + * may be returned in a Cookie request header. + */ + void setPorts(int[] ports); + +} + diff --git a/module-client/src/main/java/org/apache/http/cookie/params/CookieSpecPNames.java b/module-client/src/main/java/org/apache/http/cookie/params/CookieSpecPNames.java index e8f19a053..60df640d5 100644 --- a/module-client/src/main/java/org/apache/http/cookie/params/CookieSpecPNames.java +++ b/module-client/src/main/java/org/apache/http/cookie/params/CookieSpecPNames.java @@ -31,9 +31,6 @@ package org.apache.http.cookie.params; -import org.apache.http.params.HttpParams; - - /** * Parameter names for cookie specifications in HttpCookie. * diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/BasicCookie.java b/module-client/src/main/java/org/apache/http/impl/cookie/BasicCookie.java index 1593e6dff..69ff19288 100644 --- a/module-client/src/main/java/org/apache/http/impl/cookie/BasicCookie.java +++ b/module-client/src/main/java/org/apache/http/impl/cookie/BasicCookie.java @@ -126,6 +126,15 @@ public class BasicCookie implements SetCookie, ClientCookie { 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 null * if none exists. @@ -243,6 +252,15 @@ public class BasicCookie implements SetCookie, ClientCookie { 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.