Returns the currently configured cookies applicable to the specified URL, in an unmodifiable set. If disabled, this returns an empty set. @param url the URL on which to filter the returned cookies @return the currently configured cookies applicable to the specified URL, in an unmodifiable set
(final URL url)
| 2892 | * @return the currently configured cookies applicable to the specified URL, in an unmodifiable set |
| 2893 | */ |
| 2894 | public synchronized Set<Cookie> getCookies(final URL url) { |
| 2895 | final CookieManager cookieManager = getCookieManager(); |
| 2896 | |
| 2897 | if (!cookieManager.isCookiesEnabled()) { |
| 2898 | return Collections.emptySet(); |
| 2899 | } |
| 2900 | |
| 2901 | final URL normalizedUrl = HttpClientConverter.replaceForCookieIfNecessary(url); |
| 2902 | |
| 2903 | final String host = normalizedUrl.getHost(); |
| 2904 | // URLs like "about:blank" don't have cookies and we need to catch these |
| 2905 | // cases here before HttpClient complains |
| 2906 | if (host.isEmpty()) { |
| 2907 | return Collections.emptySet(); |
| 2908 | } |
| 2909 | |
| 2910 | // discard expired cookies |
| 2911 | cookieManager.clearExpired(new Date()); |
| 2912 | |
| 2913 | final Set<Cookie> matchingCookies = new LinkedHashSet<>(); |
| 2914 | HttpClientConverter.addMatching(cookieManager.getCookies(), normalizedUrl, |
| 2915 | getBrowserVersion(), matchingCookies); |
| 2916 | return Collections.unmodifiableSet(matchingCookies); |
| 2917 | } |
| 2918 | |
| 2919 | /** |
| 2920 | * Parses the given cookie and adds this to our cookie store. |