1 package emissary.util.web;
2
3 import jakarta.annotation.Nullable;
4
5 import java.util.ArrayList;
6 import java.util.List;
7
8
9
10
11
12
13 public class UrlData {
14
15 String password;
16 List<UrlRequestProperty> props;
17 String referer;
18 int responseCode;
19 byte[] theContent;
20 String theUrl;
21 int theMethod;
22 String userName;
23 String userAgent;
24
25
26
27
28
29 public UrlData(final String theUrl, final byte[] theContent, final int responseCode, final List<UrlRequestProperty> props) {
30 this.theUrl = theUrl;
31 this.theContent = theContent;
32 this.responseCode = responseCode;
33 this.theMethod = Url.GET;
34 this.props = new ArrayList<>(props);
35 }
36
37 public UrlData() {}
38
39 public UrlData(final String theUrl) {
40 this.theUrl = theUrl;
41 }
42
43
44
45
46
47
48 public int getResponseCode() {
49 return this.responseCode;
50 }
51
52
53
54
55
56
57 public void setResponseCode(final int v) {
58 this.responseCode = v;
59 }
60
61
62
63
64
65
66 public String getTheUrl() {
67 return this.theUrl;
68 }
69
70
71
72
73
74
75 public void setTheUrl(final String v) {
76 this.theUrl = v;
77 }
78
79
80
81
82
83
84 public byte[] getTheContent() {
85 return this.theContent;
86 }
87
88 public int getContentLength() {
89 return (this.theContent == null) ? 0 : this.theContent.length;
90 }
91
92
93
94
95
96
97 public void setTheContent(final byte[] v) {
98 this.theContent = v;
99 }
100
101
102
103
104
105
106 public String getReferer() {
107 return this.referer;
108 }
109
110
111
112
113
114
115 public void setReferer(final String v) {
116 this.referer = v;
117 }
118
119
120
121
122
123
124 public String getUserAgent() {
125 return this.userAgent;
126 }
127
128
129
130
131
132
133 public void setUserAgent(final String v) {
134 this.userAgent = v;
135 }
136
137
138
139
140
141
142 public String getUserName() {
143 return this.userName;
144 }
145
146
147
148
149
150
151 public void setUserName(final String v) {
152 this.userName = v;
153 }
154
155
156
157
158
159
160 public String getPassword() {
161 return this.password;
162 }
163
164
165
166
167
168
169 public void setPassword(final String v) {
170 this.password = v;
171 }
172
173
174
175
176
177
178 public int getTheMethod() {
179 return this.theMethod;
180 }
181
182
183
184
185
186
187 @Nullable
188 public List<UrlRequestProperty> getProps() {
189 return this.props == null ? null : new ArrayList<>(this.props);
190 }
191
192 public int getNumberOfProperties() {
193 return (this.props == null) ? 0 : this.props.size();
194 }
195
196
197
198
199
200
201 public void setProps(final List<UrlRequestProperty> v) {
202 this.props = new ArrayList<>(v);
203 }
204
205
206
207
208
209
210 public void addProp(@Nullable final UrlRequestProperty v) {
211
212 if (v == null) {
213 return;
214 }
215
216 if (this.props == null) {
217 this.props = new ArrayList<>();
218 }
219
220 this.props.add(v);
221 }
222
223
224
225
226
227
228 public void addProps(@Nullable final List<UrlRequestProperty> v) {
229 if (v == null) {
230 return;
231 }
232 if (v.isEmpty()) {
233 return;
234 }
235
236 if (this.props == null) {
237 this.props = new ArrayList<>();
238 }
239
240 this.props.addAll(v);
241 }
242
243
244
245
246
247
248 public void setTheMethod(final int v) {
249 this.theMethod = v;
250 }
251
252
253
254
255 private StringBuilder toStringBuilder(final boolean headers) {
256 final StringBuilder sb = new StringBuilder();
257 sb.append(Url.theMethodString[this.theMethod]).append(": ").append(this.theUrl).append(" ").append(this.responseCode).append("/")
258 .append(this.theContent.length);
259 if (headers && (this.props != null)) {
260 for (UrlRequestProperty prop : this.props) {
261 sb.append(prop.toString());
262 }
263 }
264 sb.append("\n\n").append(new String(this.theContent)).append("\n");
265 return sb;
266 }
267
268 @Override
269 public String toString() {
270 return this.toStringBuilder(false).toString();
271 }
272
273 public String toString(final boolean headers) {
274 return this.toStringBuilder(headers).toString();
275 }
276 }