Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ViaHeaderValue.cs
Go to the documentation of this file.
1
using
System.Diagnostics.CodeAnalysis
;
2
using
System.Globalization
;
3
using
System.Text
;
4
5
namespace
System.Net.Http.Headers
;
6
7
public
class
ViaHeaderValue
:
ICloneable
8
{
9
private
readonly
string
_protocolName
;
10
11
private
readonly
string
_protocolVersion
;
12
13
private
readonly
string
_receivedBy
;
14
15
private
readonly
string
_comment
;
16
17
public
string
?
ProtocolName
=>
_protocolName
;
18
19
public
string
ProtocolVersion
=>
_protocolVersion
;
20
21
public
string
ReceivedBy
=>
_receivedBy
;
22
23
public
string
?
Comment
=>
_comment
;
24
25
public
ViaHeaderValue
(
string
protocolVersion,
string
receivedBy)
26
: this(protocolVersion, receivedBy, null, null)
27
{
28
}
29
30
public
ViaHeaderValue
(
string
protocolVersion,
string
receivedBy,
string
? protocolName)
31
: this(protocolVersion, receivedBy, protocolName, null)
32
{
33
}
34
35
public
ViaHeaderValue
(
string
protocolVersion,
string
receivedBy,
string
? protocolName,
string
? comment)
36
{
37
HeaderUtilities
.
CheckValidToken
(protocolVersion,
"protocolVersion"
);
38
CheckReceivedBy
(receivedBy);
39
if
(!
string
.IsNullOrEmpty(protocolName))
40
{
41
HeaderUtilities
.
CheckValidToken
(protocolName,
"protocolName"
);
42
_protocolName
= protocolName;
43
}
44
if
(!
string
.IsNullOrEmpty(comment))
45
{
46
HeaderUtilities
.
CheckValidComment
(comment,
"comment"
);
47
_comment
= comment;
48
}
49
_protocolVersion
= protocolVersion;
50
_receivedBy
= receivedBy;
51
}
52
53
private
ViaHeaderValue
(
ViaHeaderValue
source
)
54
{
55
_protocolName
=
source
._protocolName;
56
_protocolVersion
=
source
._protocolVersion;
57
_receivedBy
=
source
._receivedBy;
58
_comment
=
source
._comment;
59
}
60
61
public
override
string
ToString
()
62
{
63
StringBuilder
stringBuilder =
System
.
Text
.
StringBuilderCache
.
Acquire
();
64
if
(!
string
.IsNullOrEmpty(
_protocolName
))
65
{
66
stringBuilder.
Append
(
_protocolName
);
67
stringBuilder.
Append
(
'/'
);
68
}
69
stringBuilder.
Append
(
_protocolVersion
);
70
stringBuilder.
Append
(
' '
);
71
stringBuilder.
Append
(
_receivedBy
);
72
if
(!
string
.IsNullOrEmpty(
_comment
))
73
{
74
stringBuilder.
Append
(
' '
);
75
stringBuilder.
Append
(
_comment
);
76
}
77
return
System
.
Text
.
StringBuilderCache
.
GetStringAndRelease
(stringBuilder);
78
}
79
80
public
override
bool
Equals
([NotNullWhen(
true
)]
object
?
obj
)
81
{
82
if
(!(
obj
is
ViaHeaderValue
viaHeaderValue))
83
{
84
return
false
;
85
}
86
if
(
string
.
Equals
(
_protocolVersion
, viaHeaderValue._protocolVersion,
StringComparison
.OrdinalIgnoreCase) &&
string
.Equals(
_receivedBy
, viaHeaderValue._receivedBy,
StringComparison
.OrdinalIgnoreCase) &&
string
.Equals(
_protocolName
, viaHeaderValue._protocolName,
StringComparison
.OrdinalIgnoreCase))
87
{
88
return
string
.Equals(
_comment
, viaHeaderValue._comment,
StringComparison
.Ordinal);
89
}
90
return
false
;
91
}
92
93
public
override
int
GetHashCode
()
94
{
95
int
num =
StringComparer
.
OrdinalIgnoreCase
.GetHashCode(
_protocolVersion
) ^
StringComparer
.
OrdinalIgnoreCase
.GetHashCode(
_receivedBy
);
96
if
(!
string
.IsNullOrEmpty(
_protocolName
))
97
{
98
num ^=
StringComparer
.
OrdinalIgnoreCase
.GetHashCode(
_protocolName
);
99
}
100
if
(!
string
.IsNullOrEmpty(
_comment
))
101
{
102
num ^=
_comment
.GetHashCode();
103
}
104
return
num;
105
}
106
107
public
static
ViaHeaderValue
Parse
(
string
?
input
)
108
{
109
int
index
= 0;
110
return
(
ViaHeaderValue
)
GenericHeaderParser
.
SingleValueViaParser
.ParseValue(
input
,
null
, ref
index
);
111
}
112
113
public
static
bool
TryParse
([NotNullWhen(
true
)]
string
?
input
, [NotNullWhen(
true
)] out
ViaHeaderValue
? parsedValue)
114
{
115
int
index
= 0;
116
parsedValue =
null
;
117
if
(
GenericHeaderParser
.
SingleValueViaParser
.TryParseValue(
input
,
null
, ref
index
, out var parsedValue2))
118
{
119
parsedValue = (
ViaHeaderValue
)parsedValue2;
120
return
true
;
121
}
122
return
false
;
123
}
124
125
internal
static
int
GetViaLength
(
string
input
,
int
startIndex
, out
object
parsedValue)
126
{
127
parsedValue =
null
;
128
if
(
string
.IsNullOrEmpty(
input
) ||
startIndex
>=
input
.Length)
129
{
130
return
0;
131
}
132
int
protocolEndIndex =
GetProtocolEndIndex
(
input
,
startIndex
, out var protocolName, out var protocolVersion);
133
if
(protocolEndIndex ==
startIndex
|| protocolEndIndex ==
input
.Length)
134
{
135
return
0;
136
}
137
string
host;
138
int
hostLength =
HttpRuleParser
.
GetHostLength
(
input
, protocolEndIndex, allowToken:
true
, out host);
139
if
(hostLength == 0)
140
{
141
return
0;
142
}
143
protocolEndIndex += hostLength;
144
protocolEndIndex +=
HttpRuleParser
.
GetWhitespaceLength
(
input
, protocolEndIndex);
145
string
comment =
null
;
146
if
(protocolEndIndex <
input
.Length &&
input
[protocolEndIndex] ==
'('
)
147
{
148
int
length
= 0;
149
if
(
HttpRuleParser
.
GetCommentLength
(
input
, protocolEndIndex, out
length
) != 0)
150
{
151
return
0;
152
}
153
comment =
input
.Substring(protocolEndIndex,
length
);
154
protocolEndIndex +=
length
;
155
protocolEndIndex +=
HttpRuleParser
.
GetWhitespaceLength
(
input
, protocolEndIndex);
156
}
157
parsedValue =
new
ViaHeaderValue
(protocolVersion, host, protocolName, comment);
158
return
protocolEndIndex -
startIndex
;
159
}
160
161
private
static
int
GetProtocolEndIndex
(
string
input
,
int
startIndex
, out
string
protocolName, out
string
protocolVersion)
162
{
163
protocolName =
null
;
164
protocolVersion =
null
;
165
int
startIndex2 =
startIndex
;
166
int
tokenLength =
HttpRuleParser
.
GetTokenLength
(
input
, startIndex2);
167
if
(tokenLength == 0)
168
{
169
return
0;
170
}
171
startIndex2 =
startIndex
+ tokenLength;
172
int
whitespaceLength =
HttpRuleParser
.
GetWhitespaceLength
(
input
, startIndex2);
173
startIndex2 += whitespaceLength;
174
if
(startIndex2 ==
input
.Length)
175
{
176
return
0;
177
}
178
if
(
input
[startIndex2] ==
'/'
)
179
{
180
protocolName =
input
.Substring(
startIndex
, tokenLength);
181
startIndex2++;
182
startIndex2 +=
HttpRuleParser
.
GetWhitespaceLength
(
input
, startIndex2);
183
tokenLength =
HttpRuleParser
.
GetTokenLength
(
input
, startIndex2);
184
if
(tokenLength == 0)
185
{
186
return
0;
187
}
188
protocolVersion =
input
.Substring(startIndex2, tokenLength);
189
startIndex2 += tokenLength;
190
whitespaceLength =
HttpRuleParser
.
GetWhitespaceLength
(
input
, startIndex2);
191
startIndex2 += whitespaceLength;
192
}
193
else
194
{
195
protocolVersion =
input
.Substring(
startIndex
, tokenLength);
196
}
197
if
(whitespaceLength == 0)
198
{
199
return
0;
200
}
201
return
startIndex2;
202
}
203
204
object
ICloneable
.
Clone
()
205
{
206
return
new
ViaHeaderValue
(
this
);
207
}
208
209
private
static
void
CheckReceivedBy
(
string
receivedBy)
210
{
211
if
(
string
.IsNullOrEmpty(receivedBy))
212
{
213
throw
new
ArgumentException
(
System
.
SR
.
net_http_argument_empty_string
,
"receivedBy"
);
214
}
215
if
(
HttpRuleParser
.
GetHostLength
(receivedBy, 0, allowToken:
true
, out var _) != receivedBy.Length)
216
{
217
throw
new
FormatException
(
System
.
SR
.
Format
(
CultureInfo
.
InvariantCulture
,
System
.
SR
.
net_http_headers_invalid_value
, receivedBy));
218
}
219
}
220
}
System.ArgumentException
Definition
ArgumentException.cs:9
System.FormatException
Definition
FormatException.cs:9
System.Globalization.CultureInfo.InvariantCulture
static CultureInfo InvariantCulture
Definition
CultureInfo.cs:144
System.Globalization.CultureInfo
Definition
CultureInfo.cs:8
System.Net.Http.Headers.GenericHeaderParser.SingleValueViaParser
static readonly GenericHeaderParser SingleValueViaParser
Definition
GenericHeaderParser.cs:49
System.Net.Http.Headers.GenericHeaderParser
Definition
GenericHeaderParser.cs:6
System.Net.Http.Headers.HeaderUtilities.CheckValidComment
static void CheckValidComment(string value, string parameterName)
Definition
HeaderUtilities.cs:117
System.Net.Http.Headers.HeaderUtilities.CheckValidToken
static void CheckValidToken(string value, string parameterName)
Definition
HeaderUtilities.cs:105
System.Net.Http.Headers.HeaderUtilities
Definition
HeaderUtilities.cs:9
System.Net.Http.Headers.ViaHeaderValue.CheckReceivedBy
static void CheckReceivedBy(string receivedBy)
Definition
ViaHeaderValue.cs:209
System.Net.Http.Headers.ViaHeaderValue.Equals
override bool Equals([NotNullWhen(true)] object? obj)
Definition
ViaHeaderValue.cs:80
System.Net.Http.Headers.ViaHeaderValue.ProtocolVersion
string ProtocolVersion
Definition
ViaHeaderValue.cs:19
System.Net.Http.Headers.ViaHeaderValue.GetProtocolEndIndex
static int GetProtocolEndIndex(string input, int startIndex, out string protocolName, out string protocolVersion)
Definition
ViaHeaderValue.cs:161
System.Net.Http.Headers.ViaHeaderValue.ViaHeaderValue
ViaHeaderValue(string protocolVersion, string receivedBy)
Definition
ViaHeaderValue.cs:25
System.Net.Http.Headers.ViaHeaderValue.ViaHeaderValue
ViaHeaderValue(ViaHeaderValue source)
Definition
ViaHeaderValue.cs:53
System.Net.Http.Headers.ViaHeaderValue.GetHashCode
override int GetHashCode()
Definition
ViaHeaderValue.cs:93
System.Net.Http.Headers.ViaHeaderValue.ReceivedBy
string ReceivedBy
Definition
ViaHeaderValue.cs:21
System.Net.Http.Headers.ViaHeaderValue.ViaHeaderValue
ViaHeaderValue(string protocolVersion, string receivedBy, string? protocolName, string? comment)
Definition
ViaHeaderValue.cs:35
System.Net.Http.Headers.ViaHeaderValue.Parse
static ViaHeaderValue Parse(string? input)
Definition
ViaHeaderValue.cs:107
System.Net.Http.Headers.ViaHeaderValue.ToString
override string ToString()
Definition
ViaHeaderValue.cs:61
System.Net.Http.Headers.ViaHeaderValue._comment
readonly string _comment
Definition
ViaHeaderValue.cs:15
System.Net.Http.Headers.ViaHeaderValue.GetViaLength
static int GetViaLength(string input, int startIndex, out object parsedValue)
Definition
ViaHeaderValue.cs:125
System.Net.Http.Headers.ViaHeaderValue._protocolName
readonly string _protocolName
Definition
ViaHeaderValue.cs:9
System.Net.Http.Headers.ViaHeaderValue._receivedBy
readonly string _receivedBy
Definition
ViaHeaderValue.cs:13
System.Net.Http.Headers.ViaHeaderValue.ViaHeaderValue
ViaHeaderValue(string protocolVersion, string receivedBy, string? protocolName)
Definition
ViaHeaderValue.cs:30
System.Net.Http.Headers.ViaHeaderValue.Comment
string? Comment
Definition
ViaHeaderValue.cs:23
System.Net.Http.Headers.ViaHeaderValue.TryParse
static bool TryParse([NotNullWhen(true)] string? input, [NotNullWhen(true)] out ViaHeaderValue? parsedValue)
Definition
ViaHeaderValue.cs:113
System.Net.Http.Headers.ViaHeaderValue._protocolVersion
readonly string _protocolVersion
Definition
ViaHeaderValue.cs:11
System.Net.Http.Headers.ViaHeaderValue.ProtocolName
string? ProtocolName
Definition
ViaHeaderValue.cs:17
System.Net.Http.Headers.ViaHeaderValue
Definition
ViaHeaderValue.cs:8
System.Net.Http.HttpRuleParser.GetCommentLength
static HttpParseResult GetCommentLength(string input, int startIndex, out int length)
Definition
HttpRuleParser.cs:182
System.Net.Http.HttpRuleParser.GetHostLength
static int GetHostLength(string input, int startIndex, bool allowToken, out string host)
Definition
HttpRuleParser.cs:140
System.Net.Http.HttpRuleParser.GetTokenLength
static int GetTokenLength(string input, int startIndex)
Definition
HttpRuleParser.cs:47
System.Net.Http.HttpRuleParser.GetWhitespaceLength
static int GetWhitespaceLength(string input, int startIndex)
Definition
HttpRuleParser.cs:92
System.Net.Http.HttpRuleParser
Definition
HttpRuleParser.cs:6
System.SR.Format
static string Format(string resourceFormat, object p1)
Definition
SR.cs:118
System.SR.net_http_headers_invalid_value
static string net_http_headers_invalid_value
Definition
SR.cs:26
System.SR.net_http_argument_empty_string
static string net_http_argument_empty_string
Definition
SR.cs:52
System.SR
Definition
SR.cs:7
System.StringComparer.OrdinalIgnoreCase
static StringComparer OrdinalIgnoreCase
Definition
StringComparer.cs:23
System.StringComparer
Definition
StringComparer.cs:12
System.Text.StringBuilderCache.GetStringAndRelease
static string GetStringAndRelease(StringBuilder sb)
Definition
StringBuilderCache.cs:31
System.Text.StringBuilderCache.Acquire
static StringBuilder Acquire(int capacity=16)
Definition
StringBuilderCache.cs:8
System.Text.StringBuilderCache
Definition
StringBuilderCache.cs:4
System.Text.StringBuilder.Append
StringBuilder Append(char value, int repeatCount)
Definition
StringBuilder.cs:744
System.Text.StringBuilder
Definition
StringBuilder.cs:14
System.ICloneable.Clone
object Clone()
System.ICloneable
Definition
ICloneable.cs:4
System.Diagnostics.CodeAnalysis
Definition
AllowNullAttribute.cs:1
System.Globalization
Definition
Calendar.cs:1
System.Net.Http.Headers
Definition
AltSvcHeaderParser.cs:4
System.Net.CookieToken.Equals
@ Equals
System.Text
Definition
ConsoleEncoding.cs:1
System.ExceptionArgument.startIndex
@ startIndex
System.ExceptionArgument.length
@ length
System.ExceptionArgument.source
@ source
System.ExceptionArgument.index
@ index
System.ExceptionArgument.input
@ input
System.ExceptionArgument.obj
@ obj
System.StringComparison
StringComparison
Definition
StringComparison.cs:4
System
Definition
BlockingCollection.cs:8
source
System.Net.Http
System.Net.Http.Headers
ViaHeaderValue.cs
Generated by
1.10.0