CookiePolicy
Stay organized with collections
Save and categorize content based on your preferences.
CookiePolicy implementations decide which cookies should be accepted
and which should be rejected. Three pre-defined policy implementations
are provided, namely ACCEPT_ALL, ACCEPT_NONE and ACCEPT_ORIGINAL_SERVER.
See RFC 2965 sec. 3.3 and 7 for more detail.
Fields
public
static
final
CookiePolicy
ACCEPT_ALL
One pre-defined policy which accepts all cookies.
public
static
final
CookiePolicy
ACCEPT_NONE
One pre-defined policy which accepts no cookies.
public
static
final
CookiePolicy
ACCEPT_ORIGINAL_SERVER
One pre-defined policy which only accepts cookies from original server.
Public Methods
public
abstract
boolean
shouldAccept
(URI uri, HttpCookie cookie)
Will be called to see whether or not this cookie should be accepted.
Parameters
uri |
the URI to consult accept policy with |
cookie |
the HttpCookie object in question |
Returns
true
if this cookie should be accepted;
otherwise, false
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eCookiePolicy\u003c/code\u003e interface determines which cookies are accepted or rejected.\u003c/p\u003e\n"],["\u003cp\u003eThree pre-defined implementations are available: \u003ccode\u003eACCEPT_ALL\u003c/code\u003e, \u003ccode\u003eACCEPT_NONE\u003c/code\u003e, and \u003ccode\u003eACCEPT_ORIGINAL_SERVER\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can define custom policies by implementing the \u003ccode\u003eshouldAccept\u003c/code\u003e method, which decides whether a given cookie should be accepted based on its URI and properties.\u003c/p\u003e\n"]]],[],null,["# CookiePolicy\n\npublic interface **CookiePolicy** \nCookiePolicy implementations decide which cookies should be accepted\nand which should be rejected. Three pre-defined policy implementations\nare provided, namely ACCEPT_ALL, ACCEPT_NONE and ACCEPT_ORIGINAL_SERVER.\n\nSee RFC 2965 sec. 3.3 and 7 for more detail. \n\n### Field Summary\n\n|-----------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------|\n| public static final [CookiePolicy](../../../reference/java/net/CookiePolicy.html) | [ACCEPT_ALL](../../../reference/java/net/CookiePolicy.html#ACCEPT_ALL) | One pre-defined policy which accepts all cookies. |\n| public static final [CookiePolicy](../../../reference/java/net/CookiePolicy.html) | [ACCEPT_NONE](../../../reference/java/net/CookiePolicy.html#ACCEPT_NONE) | One pre-defined policy which accepts no cookies. |\n| public static final [CookiePolicy](../../../reference/java/net/CookiePolicy.html) | [ACCEPT_ORIGINAL_SERVER](../../../reference/java/net/CookiePolicy.html#ACCEPT_ORIGINAL_SERVER) | One pre-defined policy which only accepts cookies from original server. |\n\n### Public Method Summary\n\n|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract boolean | [shouldAccept](../../../reference/java/net/CookiePolicy.html#shouldAccept(java.net.URI,%20java.net.HttpCookie))([URI](../../../reference/java/net/URI.html) uri, [HttpCookie](../../../reference/java/net/HttpCookie.html) cookie) Will be called to see whether or not this cookie should be accepted. |\n\nFields\n------\n\n#### public static final CookiePolicy\n**ACCEPT_ALL**\n\nOne pre-defined policy which accepts all cookies. \n\n#### public static final CookiePolicy\n**ACCEPT_NONE**\n\nOne pre-defined policy which accepts no cookies. \n\n#### public static final CookiePolicy\n**ACCEPT_ORIGINAL_SERVER**\n\nOne pre-defined policy which only accepts cookies from original server.\n\nPublic Methods\n--------------\n\n#### public abstract boolean\n**shouldAccept**\n([URI](../../../reference/java/net/URI.html) uri, [HttpCookie](../../../reference/java/net/HttpCookie.html) cookie)\n\nWill be called to see whether or not this cookie should be accepted. \n\n##### Parameters\n\n| uri | the URI to consult accept policy with |\n| cookie | the HttpCookie object in question |\n|--------|---------------------------------------|\n\n##### Returns\n\n- `true` if this cookie should be accepted; otherwise, `false`"]]