Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CacheControlHeaderValue.cs
Go to the documentation of this file.
4using System.Text;
5
7
9{
11
13
14 private bool _noCache;
15
17
18 private bool _noStore;
19
20 private TimeSpan? _maxAge;
21
23
24 private bool _maxStale;
25
27
29
30 private bool _noTransform;
31
32 private bool _onlyIfCached;
33
34 private bool _publicField;
35
36 private bool _privateField;
37
39
40 private bool _mustRevalidate;
41
42 private bool _proxyRevalidate;
43
45
46 public bool NoCache
47 {
48 get
49 {
50 return _noCache;
51 }
52 set
53 {
55 }
56 }
57
59
60 public bool NoStore
61 {
62 get
63 {
64 return _noStore;
65 }
66 set
67 {
69 }
70 }
71
73 {
74 get
75 {
76 return _maxAge;
77 }
78 set
79 {
80 _maxAge = value;
81 }
82 }
83
85 {
86 get
87 {
88 return _sharedMaxAge;
89 }
90 set
91 {
93 }
94 }
95
96 public bool MaxStale
97 {
98 get
99 {
100 return _maxStale;
101 }
102 set
103 {
105 }
106 }
107
109 {
110 get
111 {
112 return _maxStaleLimit;
113 }
114 set
115 {
117 }
118 }
119
121 {
122 get
123 {
124 return _minFresh;
125 }
126 set
127 {
129 }
130 }
131
132 public bool NoTransform
133 {
134 get
135 {
136 return _noTransform;
137 }
138 set
139 {
141 }
142 }
143
144 public bool OnlyIfCached
145 {
146 get
147 {
148 return _onlyIfCached;
149 }
150 set
151 {
153 }
154 }
155
156 public bool Public
157 {
158 get
159 {
160 return _publicField;
161 }
162 set
163 {
165 }
166 }
167
168 public bool Private
169 {
170 get
171 {
172 return _privateField;
173 }
174 set
175 {
177 }
178 }
179
181
182 public bool MustRevalidate
183 {
184 get
185 {
186 return _mustRevalidate;
187 }
188 set
189 {
191 }
192 }
193
194 public bool ProxyRevalidate
195 {
196 get
197 {
198 return _proxyRevalidate;
199 }
200 set
201 {
203 }
204 }
205
207
209 {
210 }
211
213 {
214 _noCache = source._noCache;
215 _noStore = source._noStore;
216 _maxAge = source._maxAge;
217 _sharedMaxAge = source._sharedMaxAge;
218 _maxStale = source._maxStale;
219 _maxStaleLimit = source._maxStaleLimit;
220 _minFresh = source._minFresh;
221 _noTransform = source._noTransform;
222 _onlyIfCached = source._onlyIfCached;
223 _publicField = source._publicField;
224 _privateField = source._privateField;
225 _mustRevalidate = source._mustRevalidate;
226 _proxyRevalidate = source._proxyRevalidate;
227 if (source._noCacheHeaders != null)
228 {
229 foreach (string noCacheHeader in source._noCacheHeaders)
230 {
232 }
233 }
234 if (source._privateHeaders != null)
235 {
236 foreach (string privateHeader in source._privateHeaders)
237 {
239 }
240 }
241 _extensions = source._extensions.Clone();
242 }
243
244 public override string ToString()
245 {
253 if (_noCache)
254 {
256 if (_noCacheHeaders != null && _noCacheHeaders.Count > 0)
257 {
258 stringBuilder.Append("=\"");
260 stringBuilder.Append('"');
261 }
262 }
263 if (_maxAge.HasValue)
264 {
266 stringBuilder.Append('=');
267 int num = (int)_maxAge.GetValueOrDefault().TotalSeconds;
268 if (num >= 0)
269 {
270 stringBuilder.Append(num);
271 }
272 else
273 {
279 handler.AppendFormatted(num);
280 stringBuilder3.Append(provider, ref handler);
281 }
282 }
283 if (_sharedMaxAge.HasValue)
284 {
286 stringBuilder.Append('=');
287 int num2 = (int)_sharedMaxAge.GetValueOrDefault().TotalSeconds;
288 if (num2 >= 0)
289 {
290 stringBuilder.Append(num2);
291 }
292 else
293 {
299 handler2.AppendFormatted(num2);
301 }
302 }
303 if (_maxStale)
304 {
306 if (_maxStaleLimit.HasValue)
307 {
308 stringBuilder.Append('=');
309 int num3 = (int)_maxStaleLimit.GetValueOrDefault().TotalSeconds;
310 if (num3 >= 0)
311 {
312 stringBuilder.Append(num3);
313 }
314 else
315 {
321 handler3.AppendFormatted(num3);
323 }
324 }
325 }
326 if (_minFresh.HasValue)
327 {
329 stringBuilder.Append('=');
330 int num4 = (int)_minFresh.GetValueOrDefault().TotalSeconds;
331 if (num4 >= 0)
332 {
333 stringBuilder.Append(num4);
334 }
335 else
336 {
342 handler4.AppendFormatted(num4);
344 }
345 }
346 if (_privateField)
347 {
349 if (_privateHeaders != null && _privateHeaders.Count > 0)
350 {
351 stringBuilder.Append("=\"");
353 stringBuilder.Append('"');
354 }
355 }
358 }
359
360 public override bool Equals([NotNullWhen(true)] object? obj)
361 {
363 {
364 return false;
365 }
367 {
370 if (sharedMaxAge.HasValue == sharedMaxAge2.HasValue && (!sharedMaxAge.HasValue || !(sharedMaxAge.GetValueOrDefault() != sharedMaxAge2.GetValueOrDefault())) && _maxStale == cacheControlHeaderValue._maxStale && !(_maxStaleLimit != cacheControlHeaderValue._maxStaleLimit))
371 {
374 if (sharedMaxAge.HasValue == sharedMaxAge2.HasValue && (!sharedMaxAge.HasValue || !(sharedMaxAge.GetValueOrDefault() != sharedMaxAge2.GetValueOrDefault())) && _noTransform == cacheControlHeaderValue._noTransform && _onlyIfCached == cacheControlHeaderValue._onlyIfCached && _publicField == cacheControlHeaderValue._publicField && _privateField == cacheControlHeaderValue._privateField && _mustRevalidate == cacheControlHeaderValue._mustRevalidate && _proxyRevalidate == cacheControlHeaderValue._proxyRevalidate)
375 {
377 {
378 return false;
379 }
381 {
382 return false;
383 }
384 if (!HeaderUtilities.AreEqualCollections(_extensions, cacheControlHeaderValue._extensions))
385 {
386 return false;
387 }
388 return true;
389 }
390 }
391 }
392 return false;
393 }
394
395 public override int GetHashCode()
396 {
397 int num = _noCache.GetHashCode() ^ (_noStore.GetHashCode() << 1) ^ (_maxStale.GetHashCode() << 2) ^ (_noTransform.GetHashCode() << 3) ^ (_onlyIfCached.GetHashCode() << 4) ^ (_publicField.GetHashCode() << 5) ^ (_privateField.GetHashCode() << 6) ^ (_mustRevalidate.GetHashCode() << 7) ^ (_proxyRevalidate.GetHashCode() << 8);
398 num = num ^ (_maxAge.HasValue ? (_maxAge.Value.GetHashCode() ^ 1) : 0) ^ (_sharedMaxAge.HasValue ? (_sharedMaxAge.Value.GetHashCode() ^ 2) : 0) ^ (_maxStaleLimit.HasValue ? (_maxStaleLimit.Value.GetHashCode() ^ 4) : 0) ^ (_minFresh.HasValue ? (_minFresh.Value.GetHashCode() ^ 8) : 0);
399 if (_noCacheHeaders != null && _noCacheHeaders.Count > 0)
400 {
401 foreach (string noCacheHeader in _noCacheHeaders)
402 {
404 }
405 }
406 if (_privateHeaders != null && _privateHeaders.Count > 0)
407 {
408 foreach (string privateHeader in _privateHeaders)
409 {
411 }
412 }
413 if (_extensions != null && _extensions.Count > 0)
414 {
416 {
417 num ^= extension.GetHashCode();
418 }
419 }
420 return num;
421 }
422
423 public static CacheControlHeaderValue Parse(string? input)
424 {
425 int index = 0;
427 }
428
430 {
431 int index = 0;
432 parsedValue = null;
434 {
436 return true;
437 }
438 return false;
439 }
440
442 {
443 parsedValue = null;
444 if (string.IsNullOrEmpty(input) || startIndex >= input.Length)
445 {
446 return 0;
447 }
448 int index = startIndex;
450 while (index < input.Length)
451 {
452 if (!s_nameValueListParser.TryParseValue(input, null, ref index, out var parsedValue2))
453 {
454 return 0;
455 }
457 }
459 if (cacheControlHeaderValue == null)
460 {
462 }
464 {
465 return 0;
466 }
467 if (storeValue == null)
468 {
470 }
471 return input.Length - startIndex;
472 }
473
475 {
477 {
478 bool flag = true;
479 switch (nameValue.Name.ToLowerInvariant())
480 {
481 case "no-cache":
482 flag = TrySetOptionalTokenList(nameValue, ref cc._noCache, ref cc._noCacheHeaders);
483 break;
484 case "no-store":
485 flag = TrySetTokenOnlyValue(nameValue, ref cc._noStore);
486 break;
487 case "max-age":
488 flag = TrySetTimeSpan(nameValue, ref cc._maxAge);
489 break;
490 case "max-stale":
491 flag = nameValue.Value == null || TrySetTimeSpan(nameValue, ref cc._maxStaleLimit);
492 if (flag)
493 {
494 cc._maxStale = true;
495 }
496 break;
497 case "min-fresh":
498 flag = TrySetTimeSpan(nameValue, ref cc._minFresh);
499 break;
500 case "no-transform":
501 flag = TrySetTokenOnlyValue(nameValue, ref cc._noTransform);
502 break;
503 case "only-if-cached":
504 flag = TrySetTokenOnlyValue(nameValue, ref cc._onlyIfCached);
505 break;
506 case "public":
507 flag = TrySetTokenOnlyValue(nameValue, ref cc._publicField);
508 break;
509 case "private":
510 flag = TrySetOptionalTokenList(nameValue, ref cc._privateField, ref cc._privateHeaders);
511 break;
512 case "must-revalidate":
513 flag = TrySetTokenOnlyValue(nameValue, ref cc._mustRevalidate);
514 break;
515 case "proxy-revalidate":
516 flag = TrySetTokenOnlyValue(nameValue, ref cc._proxyRevalidate);
517 break;
518 case "s-maxage":
519 flag = TrySetTimeSpan(nameValue, ref cc._sharedMaxAge);
520 break;
521 default:
522 cc.Extensions.Add(nameValue);
523 break;
524 }
525 if (!flag)
526 {
527 return false;
528 }
529 }
530 return true;
531 }
532
534 {
535 if (nameValue.Value != null)
536 {
537 return false;
538 }
539 boolField = true;
540 return true;
541 }
542
544 {
545 if (nameValue.Value == null)
546 {
547 boolField = true;
548 return true;
549 }
550 string value = nameValue.Value;
551 if (value.Length < 3 || value[0] != '"' || value[value.Length - 1] != '"')
552 {
553 return false;
554 }
555 int num = 1;
556 int num2 = value.Length - 1;
557 bool separatorFound = false;
558 int num3 = ((destination != null) ? destination.Count : 0);
559 while (num < num2)
560 {
562 if (num == num2)
563 {
564 break;
565 }
567 if (tokenLength == 0)
568 {
569 return false;
570 }
571 if (destination == null)
572 {
574 }
575 destination.Add(value.Substring(num, tokenLength));
576 num += tokenLength;
577 }
578 if (destination != null && destination.Count > num3)
579 {
580 boolField = true;
581 return true;
582 }
583 return false;
584 }
585
587 {
588 if (nameValue.Value == null)
589 {
590 return false;
591 }
592 if (!HeaderUtilities.TryParseInt32(nameValue.Value, out var result))
593 {
594 return false;
595 }
596 timeSpan = new TimeSpan(0, 0, result);
597 return true;
598 }
599
600 private static void AppendValueIfRequired(StringBuilder sb, bool appendValue, string value)
601 {
602 if (appendValue)
603 {
605 }
606 }
607
609 {
610 if (sb.Length > 0)
611 {
612 sb.Append(", ");
613 }
614 sb.Append(value);
615 }
616
618 {
619 bool flag = true;
620 foreach (string value in values)
621 {
622 if (flag)
623 {
624 flag = false;
625 }
626 else
627 {
628 sb.Append(", ");
629 }
630 sb.Append(value);
631 }
632 }
633
634 private static void CheckIsValidToken(string item)
635 {
637 }
638
640 {
641 return new CacheControlHeaderValue(this);
642 }
643}
void Add(TKey key, TValue value)
static readonly CacheControlHeaderParser Parser
static void AppendValueIfRequired(StringBuilder sb, bool appendValue, string value)
static CacheControlHeaderValue Parse(string? input)
static void AppendValues(StringBuilder sb, ObjectCollection< string > values)
ObjectCollection< NameValueHeaderValue > _extensions
static bool TrySetOptionalTokenList(NameValueHeaderValue nameValue, ref bool boolField, ref ObjectCollection< string > destination)
static bool TrySetTimeSpan(NameValueHeaderValue nameValue, ref TimeSpan? timeSpan)
static int GetCacheControlLength(string input, int startIndex, CacheControlHeaderValue storeValue, out CacheControlHeaderValue parsedValue)
override bool Equals([NotNullWhen(true)] object? obj)
static bool TryParse(string? input, out CacheControlHeaderValue? parsedValue)
static void AppendValueWithSeparatorIfRequired(StringBuilder sb, string value)
static bool TrySetCacheControlValues(CacheControlHeaderValue cc, List< NameValueHeaderValue > nameValueList)
static bool TrySetTokenOnlyValue(NameValueHeaderValue nameValue, ref bool boolField)
static readonly GenericHeaderParser MultipleValueNameValueParser
static bool TryParseInt32(string value, out int result)
static void CheckValidToken(string value, string parameterName)
static int GetNextNonEmptyOrWhitespaceIndex(string input, int startIndex, bool skipEmptyValues, out bool separatorFound)
static int GetTokenLength(string input, int startIndex)
static StringComparer OrdinalIgnoreCase
static string GetStringAndRelease(StringBuilder sb)
static StringBuilder Acquire(int capacity=16)
StringBuilder Append(char value, int repeatCount)
double TotalSeconds
Definition TimeSpan.cs:64
override int GetHashCode()
Definition TimeSpan.cs:195