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.http.cookie;
28
29 import java.util.Locale;
30
31 import org.apache.http.annotation.Contract;
32 import org.apache.http.annotation.ThreadingBehavior;
33 import org.apache.http.util.Args;
34 import org.apache.http.util.TextUtils;
35
36
37
38
39
40
41
42 @Contract(threading = ThreadingBehavior.IMMUTABLE)
43 public final class CookieOrigin {
44
45 private final String host;
46 private final int port;
47 private final String path;
48 private final boolean secure;
49
50 public CookieOrigin(final String host, final int port, final String path, final boolean secure) {
51 super();
52 Args.notBlank(host, "Host");
53 Args.notNegative(port, "Port");
54 Args.notNull(path, "Path");
55 this.host = host.toLowerCase(Locale.ROOT);
56 this.port = port;
57 if (!TextUtils.isBlank(path)) {
58 this.path = path;
59 } else {
60 this.path = "/";
61 }
62 this.secure = secure;
63 }
64
65 public String getHost() {
66 return this.host;
67 }
68
69 public String getPath() {
70 return this.path;
71 }
72
73 public int getPort() {
74 return this.port;
75 }
76
77 public boolean isSecure() {
78 return this.secure;
79 }
80
81 @Override
82 public String toString() {
83 final StringBuilder buffer = new StringBuilder();
84 buffer.append('[');
85 if (this.secure) {
86 buffer.append("(secure)");
87 }
88 buffer.append(this.host);
89 buffer.append(':');
90 buffer.append(Integer.toString(this.port));
91 buffer.append(this.path);
92 buffer.append(']');
93 return buffer.toString();
94 }
95
96 }