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