Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HttpValidationHelpers.cs
Go to the documentation of this file.
1namespace System.Net;
2
3internal static class HttpValidationHelpers
4{
5 private static readonly char[] s_httpTrimCharacters = new char[6] { '\t', '\n', '\v', '\f', '\r', ' ' };
6
7 internal static bool ContainsNonAsciiChars(string token)
8 {
9 for (int i = 0; i < token.Length; i++)
10 {
11 if (token[i] < ' ' || token[i] > '~')
12 {
13 return true;
14 }
15 }
16 return false;
17 }
18
19 internal static bool IsValidToken(string token)
20 {
21 if (token.Length > 0 && !IsInvalidMethodOrHeaderString(token))
22 {
23 return !ContainsNonAsciiChars(token);
24 }
25 return false;
26 }
27
28 public static string CheckBadHeaderValueChars(string value)
29 {
30 if (string.IsNullOrEmpty(value))
31 {
32 return string.Empty;
33 }
35 int num = 0;
36 for (int i = 0; i < value.Length; i++)
37 {
38 char c = (char)(0xFFu & value[i]);
39 switch (num)
40 {
41 case 0:
42 if (c == '\r')
43 {
44 num = 1;
45 }
46 else if (c == '\n')
47 {
48 num = 2;
49 }
50 else if (c == '\u007f' || (c < ' ' && c != '\t'))
51 {
53 }
54 break;
55 case 1:
56 if (c == '\n')
57 {
58 num = 2;
59 break;
60 }
62 case 2:
63 if (c == ' ' || c == '\t')
64 {
65 num = 0;
66 break;
67 }
69 }
70 }
71 if (num != 0)
72 {
74 }
75 return value;
76 }
77
78 public static bool IsInvalidMethodOrHeaderString(string stringValue)
79 {
80 for (int i = 0; i < stringValue.Length; i++)
81 {
82 switch (stringValue[i])
83 {
84 case '\t':
85 case '\n':
86 case '\r':
87 case ' ':
88 case '"':
89 case '\'':
90 case '(':
91 case ')':
92 case ',':
93 case '/':
94 case ':':
95 case ';':
96 case '<':
97 case '=':
98 case '>':
99 case '?':
100 case '@':
101 case '[':
102 case '\\':
103 case ']':
104 case '{':
105 case '}':
106 return true;
107 }
108 }
109 return false;
110 }
111}
static readonly char[] s_httpTrimCharacters
static string CheckBadHeaderValueChars(string value)
static bool ContainsNonAsciiChars(string token)
static bool IsValidToken(string token)
static bool IsInvalidMethodOrHeaderString(string stringValue)
static string net_WebHeaderInvalidCRLFChars
Definition SR.cs:72
static string net_WebHeaderInvalidControlChars
Definition SR.cs:102
Definition SR.cs:7