1 /*
2 * Copyright (c) 2002-2026 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.httpclient;
16
17 import java.io.Serializable;
18 import java.util.Date;
19 import java.util.List;
20
21 import org.apache.http.client.CookieStore;
22 import org.apache.http.cookie.ClientCookie;
23 import org.apache.http.cookie.Cookie;
24 import org.htmlunit.CookieManager;
25
26 /**
27 * Implementation of {@link CookieStore} like {@link org.apache.http.impl.client.BasicCookieStore}
28 * BUT using our own {@link CookieManager} as back end.
29 *
30 * @author Marc Guillemot
31 * @author Ronald Brill
32 */
33 public final class HtmlUnitCookieStore implements CookieStore, Serializable {
34 // no synchronization required here, the CookieManager is thread-safe
35 private final CookieManager manager_;
36
37 /**
38 * Constructor.
39 *
40 * @param manager the CookieManager
41 */
42 public HtmlUnitCookieStore(final CookieManager manager) {
43 manager_ = manager;
44 }
45
46 /**
47 * {@inheritDoc}
48 */
49 @Override
50 public void addCookie(final Cookie cookie) {
51 manager_.addCookie(new HttpClientCookie((ClientCookie) cookie));
52 }
53
54 /**
55 * {@inheritDoc}
56 */
57 @Override
58 public List<Cookie> getCookies() {
59 return HttpClientConverter.toHttpClient(manager_.getCookies());
60 }
61
62 /**
63 * {@inheritDoc}
64 */
65 @Override
66 public boolean clearExpired(final Date date) {
67 return manager_.clearExpired(date);
68 }
69
70 /**
71 * {@inheritDoc}
72 */
73 @Override
74 public void clear() {
75 manager_.clearCookies();
76 }
77 }