1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements.  See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License.  You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package java.net;
18
19/**
20 * CookiePolicy has three pre-defined policy. They are ACCEPT_ALL, ACCEPT_NONE
21 * and ACCEPT_ORIGINAL_SERVER respectively. They are used to decide which
22 * cookies should be accepted and which should not be.
23 *
24 * See <a href="http://www.ietf.org/rfc/rfc2965.txt">RFC 2965</a> sections 3.3 and 7 for more detail.
25 *
26 * @since 1.6
27 */
28public interface CookiePolicy {
29
30    /**
31     * A pre-defined policy, accepts all cookies.
32     */
33    static final CookiePolicy ACCEPT_ALL = new CookiePolicy() {
34        public boolean shouldAccept(URI uri, HttpCookie cookie) {
35            return true;
36        }
37    };
38
39    /**
40     * A pre-defined policy, accepts no cookies at all.
41     */
42    static final CookiePolicy ACCEPT_NONE = new CookiePolicy() {
43        public boolean shouldAccept(URI uri, HttpCookie cookie) {
44            return false;
45        }
46    };
47
48    /**
49     * A pre-defined policy, only accepts cookies from original server.
50     */
51    static final CookiePolicy ACCEPT_ORIGINAL_SERVER = new CookiePolicy() {
52        public boolean shouldAccept(URI uri, HttpCookie cookie) {
53            return HttpCookie.domainMatches(cookie.getDomain(), uri.getHost());
54        }
55    };
56
57    /**
58     * This method is used to determine whether or not the specified cookie
59     * should be accepted.
60     *
61     * @param uri
62     *            the URI to used to determine acceptability
63     * @param cookie
64     *            the HttpCookie to be determined
65     * @return true if this cookie should be accepted; false otherwise
66     */
67    boolean shouldAccept(URI uri, HttpCookie cookie);
68}
69