View Javadoc

1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.cookie;
29  
30  import java.util.List;
31  
32  import org.apache.http.Header;
33  import org.apache.http.annotation.Obsolete;
34  
35  /**
36   * Defines the cookie management specification.
37   * <p>Cookie management specification must define
38   * <ul>
39   *   <li> rules of parsing "Set-Cookie" header
40   *   <li> rules of validation of parsed cookies
41   *   <li>  formatting of "Cookie" header
42   * </ul>
43   * for a given host, port and path of origin
44   * <p>
45   * Please do not use methods marked as @Obsolete. They have been rendered
46   * obsolete by RFC 6265.
47   *
48   * @since 4.0
49   */
50  public interface CookieSpec {
51  
52      /**
53       * Returns version of the state management this cookie specification
54       * conforms to.
55       *
56       * @return version of the state management specification
57       */
58      @Obsolete
59      int getVersion();
60  
61      /**
62        * Parse the {@code "Set-Cookie"} Header into an array of Cookies.
63        *
64        * <p>This method will not perform the validation of the resultant
65        * {@link Cookie}s</p>
66        *
67        * @see #validate
68        *
69        * @param header the {@code Set-Cookie} received from the server
70        * @param origin details of the cookie origin
71        * @return an array of {@code Cookie}s parsed from the header
72        * @throws MalformedCookieException if an exception occurs during parsing
73        */
74      List<Cookie> parse(Header header, CookieOrigin origin) throws MalformedCookieException;
75  
76      /**
77        * Validate the cookie according to validation rules defined by the
78        *  cookie specification.
79        *
80        * @param cookie the Cookie to validate
81        * @param origin details of the cookie origin
82        * @throws MalformedCookieException if the cookie is invalid
83        */
84      void validate(Cookie cookie, CookieOrigin origin) throws MalformedCookieException;
85  
86      /**
87       * Determines if a Cookie matches the target location.
88       *
89       * @param cookie the Cookie to be matched
90       * @param origin the target to test against
91       *
92       * @return {@code true} if the cookie should be submitted with a request
93       *  with given attributes, {@code false} otherwise.
94       */
95      boolean match(Cookie cookie, CookieOrigin origin);
96  
97      /**
98       * Create {@code "Cookie"} headers for an array of Cookies.
99       *
100      * @param cookies the Cookies format into a Cookie header
101      * @return a Header for the given Cookies.
102      * @throws IllegalArgumentException if an input parameter is illegal
103      */
104     List<Header> formatCookies(List<Cookie> cookies);
105 
106     /**
107      * Returns a request header identifying what version of the state management
108      * specification is understood. May be {@code null} if the cookie
109      * specification does not support {@code Cookie2} header.
110      */
111     @Obsolete
112     Header getVersionHeader();
113 
114 }