* Returns a {@link LimitedCookieStoreFacade} whose
* {@link LimitedCookieStoreFacade#getCookies()} method returns only cookies
* from {@code host} and its parent domains, if applicable.
*/
public CookieStore cookieStoreFor(String host) {
CompositeCollection cookieCollection = new CompositeCollection();
if (InternetDomainName.isValid(host)) {
InternetDomainName domain = InternetDomainName.from(host);
while (domain != null) {
Collection<Cookie> subset = hostSubset(domain.toString());
cookieCollection.addComposited(subset);
if (domain.hasParent()) {
domain = domain.parent();
} else {
domain = null;
}
}
} else {
Collection<Cookie> subset = hostSubset(host.toString());
cookieCollection.addComposited(subset);
}
@SuppressWarnings("unchecked")
List<Cookie> cookieList = new RestrictedCollectionWrappedList<Cookie>(cookieCollection);
LimitedCookieStoreFacade store = new LimitedCookieStoreFacade(cookieList);