Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ContentDispositionHeaderValue.cs
Go to the documentation of this file.
4using System.Text;
5
7
9{
11
12 private string _dispositionType;
13
14 public string DispositionType
15 {
16 get
17 {
18 return _dispositionType;
19 }
20 set
21 {
24 }
25 }
26
28
29 public string? Name
30 {
31 get
32 {
33 return GetName("name");
34 }
35 set
36 {
37 SetName("name", value);
38 }
39 }
40
41 public string? FileName
42 {
43 get
44 {
45 return GetName("filename");
46 }
47 set
48 {
49 SetName("filename", value);
50 }
51 }
52
53 public string? FileNameStar
54 {
55 get
56 {
57 return GetName("filename*");
58 }
59 set
60 {
61 SetName("filename*", value);
62 }
63 }
64
66 {
67 get
68 {
69 return GetDate("creation-date");
70 }
71 set
72 {
73 SetDate("creation-date", value);
74 }
75 }
76
78 {
79 get
80 {
81 return GetDate("modification-date");
82 }
83 set
84 {
85 SetDate("modification-date", value);
86 }
87 }
88
90 {
91 get
92 {
93 return GetDate("read-date");
94 }
95 set
96 {
97 SetDate("read-date", value);
98 }
99 }
100
101 public long? Size
102 {
103 get
104 {
106 if (nameValueHeaderValue != null)
107 {
108 string value = nameValueHeaderValue.Value;
109 if (ulong.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
110 {
111 return (long)result;
112 }
113 }
114 return null;
115 }
116 set
117 {
119 if (!value.HasValue)
120 {
121 if (nameValueHeaderValue != null)
122 {
124 }
125 return;
126 }
127 if (value < 0)
128 {
129 throw new ArgumentOutOfRangeException("value");
130 }
131 if (nameValueHeaderValue != null)
132 {
133 nameValueHeaderValue.Value = value.Value.ToString(CultureInfo.InvariantCulture);
134 return;
135 }
136 string value2 = value.Value.ToString(CultureInfo.InvariantCulture);
138 }
139 }
140
142 {
143 }
144
146 {
147 _dispositionType = source._dispositionType;
148 _parameters = source._parameters.Clone();
149 }
150
156
164
165 public override bool Equals([NotNullWhen(true)] object? obj)
166 {
168 {
169 return false;
170 }
171 if (string.Equals(_dispositionType, contentDispositionHeaderValue._dispositionType, StringComparison.OrdinalIgnoreCase))
172 {
173 return HeaderUtilities.AreEqualCollections(_parameters, contentDispositionHeaderValue._parameters);
174 }
175 return false;
176 }
177
178 public override int GetHashCode()
179 {
181 }
182
184 {
185 return new ContentDispositionHeaderValue(this);
186 }
187
189 {
190 int index = 0;
192 }
193
195 {
196 int index = 0;
197 parsedValue = null;
199 {
201 return true;
202 }
203 return false;
204 }
205
206 internal static int GetDispositionTypeLength(string input, int startIndex, out object parsedValue)
207 {
208 parsedValue = null;
209 if (string.IsNullOrEmpty(input) || startIndex >= input.Length)
210 {
211 return 0;
212 }
213 string dispositionType;
216 {
217 return 0;
218 }
222 contentDispositionHeaderValue._dispositionType = dispositionType;
223 if (num < input.Length && input[num] == ';')
224 {
225 num++;
227 if (nameValueListLength == 0)
228 {
229 return 0;
230 }
232 return num + nameValueListLength - startIndex;
233 }
235 return num - startIndex;
236 }
237
239 {
240 dispositionType = null;
242 if (tokenLength == 0)
243 {
244 return 0;
245 }
247 return tokenLength;
248 }
249
261
263 {
265 if (nameValueHeaderValue != null)
266 {
269 {
270 readOnlySpan = readOnlySpan.Slice(1, readOnlySpan.Length - 2);
271 }
273 {
274 return result;
275 }
276 }
277 return null;
278 }
279
280 private void SetDate(string parameter, DateTimeOffset? date)
281 {
283 if (!date.HasValue)
284 {
285 if (nameValueHeaderValue != null)
286 {
288 }
289 return;
290 }
291 string value = "\"" + HttpDateParser.DateToString(date.Value) + "\"";
292 if (nameValueHeaderValue != null)
293 {
294 nameValueHeaderValue.Value = value;
295 }
296 else
297 {
299 }
300 }
301
302 private string GetName(string parameter)
303 {
305 if (nameValueHeaderValue != null)
306 {
307 string output;
308 if (parameter.EndsWith('*'))
309 {
311 {
312 return output;
313 }
314 return null;
315 }
317 {
318 return output;
319 }
320 return nameValueHeaderValue.Value;
321 }
322 return null;
323 }
324
325 private void SetName(string parameter, string value)
326 {
328 if (string.IsNullOrEmpty(value))
329 {
330 if (nameValueHeaderValue != null)
331 {
333 }
334 return;
335 }
336 string empty = string.Empty;
338 if (nameValueHeaderValue != null)
339 {
340 nameValueHeaderValue.Value = empty;
341 }
342 else
343 {
345 }
346 }
347
348 private static string EncodeAndQuoteMime(string input)
349 {
350 string text = input;
351 bool flag = false;
352 if (IsQuoted(text))
353 {
354 text = text.Substring(1, text.Length - 2);
355 flag = true;
356 }
357 if (text.Contains('"'))
358 {
360 }
362 {
363 flag = true;
365 }
366 else if (!flag && HttpRuleParser.GetTokenLength(text, 0) != text.Length)
367 {
368 flag = true;
369 }
370 if (flag)
371 {
372 text = "\"" + text + "\"";
373 }
374 return text;
375 }
376
377 private static bool IsQuoted(ReadOnlySpan<char> value)
378 {
379 if (value.Length > 1 && value[0] == '"')
380 {
381 return value[value.Length - 1] == '"';
382 }
383 return false;
384 }
385
386 private static string EncodeMime(string input)
387 {
388 byte[] bytes = Encoding.UTF8.GetBytes(input);
390 return "=?utf-8?B?" + text + "?=";
391 }
392
393 private static bool TryDecodeMime(string input, [NotNullWhen(true)] out string output)
394 {
395 output = null;
396 if (!IsQuoted(input) || input.Length < 10)
397 {
398 return false;
399 }
400 string[] array = input.Split('?');
401 if (array.Length != 5 || array[0] != "\"=" || array[4] != "=\"" || array[2].ToLowerInvariant() != "b")
402 {
403 return false;
404 }
405 try
406 {
407 Encoding encoding = Encoding.GetEncoding(array[1]);
409 output = encoding.GetString(array2, 0, array2.Length);
410 return true;
411 }
412 catch (ArgumentException)
413 {
414 }
415 catch (FormatException)
416 {
417 }
418 return false;
419 }
420
421 private static bool TryDecode5987(string input, out string output)
422 {
423 output = null;
424 int num = input.IndexOf('\'');
425 if (num == -1)
426 {
427 return false;
428 }
429 int num2 = input.LastIndexOf('\'');
430 if (num == num2 || input.IndexOf('\'', num + 1) != num2)
431 {
432 return false;
433 }
434 string name = input.Substring(0, num);
435 string text = input.Substring(num2 + 1, input.Length - (num2 + 1));
437 try
438 {
439 Encoding encoding = Encoding.GetEncoding(name);
440 byte[] array = new byte[text.Length];
441 int num3 = 0;
442 for (int i = 0; i < text.Length; i++)
443 {
444 if (Uri.IsHexEncoding(text, i))
445 {
446 array[num3++] = (byte)Uri.HexUnescape(text, ref i);
447 i--;
448 continue;
449 }
450 if (num3 > 0)
451 {
452 stringBuilder.Append(encoding.GetString(array, 0, num3));
453 num3 = 0;
454 }
455 stringBuilder.Append(text[i]);
456 }
457 if (num3 > 0)
458 {
459 stringBuilder.Append(encoding.GetString(array, 0, num3));
460 }
461 }
462 catch (ArgumentException)
463 {
464 return false;
465 }
466 output = stringBuilder.ToString();
467 return true;
468 }
469}
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
static string ToBase64String(byte[] inArray)
Definition Convert.cs:2675
static unsafe byte[] FromBase64String(string s)
Definition Convert.cs:2904
static CultureInfo InvariantCulture
static string DateToString(DateTimeOffset dateTime)
static bool TryParse(ReadOnlySpan< char > input, out DateTimeOffset result)
static int GetDispositionTypeExpressionLength(string input, int startIndex, out string dispositionType)
static bool TryDecodeMime(string input, [NotNullWhen(true)] out string output)
static ContentDispositionHeaderValue Parse(string? input)
override bool Equals([NotNullWhen(true)] object? obj)
static int GetDispositionTypeLength(string input, int startIndex, out object parsedValue)
static void CheckDispositionTypeFormat(string dispositionType, string parameterName)
static bool TryParse([NotNullWhen(true)] string? input, [NotNullWhen(true)] out ContentDispositionHeaderValue? parsedValue)
static bool TryDecode5987(string input, out string output)
static readonly GenericHeaderParser ContentDispositionParser
static bool ContainsNonAscii(string input)
static string Encode5987(string input)
static int GetNameValueListLength(string input, int startIndex, char delimiter, ObjectCollection< NameValueHeaderValue > nameValueCollection)
static NameValueHeaderValue Find(ObjectCollection< NameValueHeaderValue > values, string name)
static int GetTokenLength(string input, int startIndex)
static int GetWhitespaceLength(string input, int startIndex)
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_http_headers_invalid_value
Definition SR.cs:26
static string net_http_argument_empty_string
Definition SR.cs:52
Definition SR.cs:7
static StringComparer OrdinalIgnoreCase
static Encoding UTF8
Definition Encoding.cs:526
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593
unsafe string GetString(byte *bytes, int byteCount)
Definition Encoding.cs:973
static string GetStringAndRelease(StringBuilder sb)
static StringBuilder Acquire(int capacity=16)
static bool IsHexEncoding(string pattern, int index)
Definition Uri.cs:1063
static char HexUnescape(string pattern, ref int index)
Definition Uri.cs:1045