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