1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.apache.hc.client5.http.impl.cookie;
28
29 import org.apache.hc.client5.http.cookie.CommonCookieAttributeHandler;
30 import org.apache.hc.client5.http.cookie.Cookie;
31 import org.apache.hc.client5.http.cookie.CookieOrigin;
32 import org.apache.hc.client5.http.cookie.MalformedCookieException;
33 import org.apache.hc.client5.http.cookie.SetCookie;
34 import org.apache.hc.core5.annotation.Contract;
35 import org.apache.hc.core5.annotation.ThreadingBehavior;
36 import org.apache.hc.core5.util.Args;
37
38
39
40
41
42
43 @Contract(threading = ThreadingBehavior.STATELESS)
44 public class BasicSecureHandler extends AbstractCookieAttributeHandler implements CommonCookieAttributeHandler {
45
46
47
48
49
50
51 public static final BasicSecureHandler INSTANCE = new BasicSecureHandler();
52
53 public BasicSecureHandler() {
54 super();
55 }
56
57 @Override
58 public void parse(final SetCookie cookie, final String value)
59 throws MalformedCookieException {
60 Args.notNull(cookie, "Cookie");
61 cookie.setSecure(true);
62 }
63
64 @Override
65 public boolean match(final Cookie cookie, final CookieOrigin origin) {
66 Args.notNull(cookie, "Cookie");
67 Args.notNull(origin, "Cookie origin");
68 return !cookie.isSecure() || origin.isSecure();
69 }
70
71 @Override
72 public String getAttributeName() {
73 return Cookie.SECURE_ATTR;
74 }
75
76 }