src/java.base/share/classes/java/net/CookieStore.java
author chegar
Fri, 18 Oct 2019 21:25:01 +0100
branchdatagramsocketimpl-branch
changeset 58697 e3ff12d14d43
parent 47216 71c04702a3d5
permissions -rw-r--r--
datagramsocketimpl-branch: minor refactoring
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18800
e7fa560afcfb 8020318: Fix doclint issues in java.net
juh
parents: 5506
diff changeset
     2
 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.net;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * A CookieStore object represents a storage for cookie. Can store and retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * cookies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 18800
diff changeset
    35
 * <p>{@link CookieManager} will call {@code CookieStore.add} to save cookies
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 18800
diff changeset
    36
 * for every incoming HTTP response, and call {@code CookieStore.get} to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * retrieve cookie for every outgoing HTTP request. A CookieStore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * is responsible for removing HttpCookie instances which have expired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @author Edward Wang
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public interface CookieStore {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * Adds one HTTP cookie to the store. This is called for every
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * incoming HTTP response.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * <p>A cookie to store may or may not be associated with an URI. If it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * is not associated with an URI, the cookie's domain and path attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * will indicate where it comes from. If it is associated with an URI and
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 19069
diff changeset
    51
     * its domain and path attribute are not specified, given URI will indicate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * where this cookie comes from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * <p>If a cookie corresponding to the given URI already exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * then it is replaced with the new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @param uri       the uri this cookie associated with.
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 18800
diff changeset
    58
     *                  if {@code null}, this cookie will not be associated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *                  with an URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * @param cookie    the cookie to store
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     *
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 18800
diff changeset
    62
     * @throws NullPointerException if {@code cookie} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @see #get
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public void add(URI uri, HttpCookie cookie);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Retrieve cookies associated with given URI, or whose domain matches the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * given URI. Only cookies that have not expired are returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * This is called for every outgoing HTTP request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @return          an immutable list of HttpCookie,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *                  return empty list if no cookies match the given URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
18800
e7fa560afcfb 8020318: Fix doclint issues in java.net
juh
parents: 5506
diff changeset
    78
     * @param uri       the uri associated with the cookies to be returned
e7fa560afcfb 8020318: Fix doclint issues in java.net
juh
parents: 5506
diff changeset
    79
     *
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 18800
diff changeset
    80
     * @throws NullPointerException if {@code uri} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @see #add
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public List<HttpCookie> get(URI uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Get all not-expired cookies in cookie store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @return          an immutable list of http cookies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *                  return empty list if there's no http cookie in store
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public List<HttpCookie> getCookies();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Get all URIs which identify the cookies in this cookie store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @return          an immutable list of URIs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *                  return empty list if no cookie in this cookie store
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *                  is associated with an URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public List<URI> getURIs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Remove a cookie from store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param uri       the uri this cookie associated with.
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 18800
diff changeset
   111
     *                  if {@code null}, the cookie to be removed is not associated
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 18800
diff changeset
   112
     *                  with an URI when added; if not {@code null}, the cookie
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *                  to be removed is associated with the given URI when added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @param cookie    the cookie to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 18800
diff changeset
   116
     * @return          {@code true} if this store contained the specified cookie
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 18800
diff changeset
   118
     * @throws NullPointerException if {@code cookie} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public boolean remove(URI uri, HttpCookie cookie);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Remove all cookies in this cookie store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 18800
diff changeset
   126
     * @return          {@code true} if this store changed as a result of the call
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public boolean removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
}