Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UriHeaderParser.cs
Go to the documentation of this file.
1
using
System.Diagnostics.CodeAnalysis
;
2
using
System.Text
;
3
4
namespace
System.Net.Http.Headers
;
5
6
internal
sealed
class
UriHeaderParser
:
HttpHeaderParser
7
{
8
private
readonly
UriKind
_uriKind
;
9
10
internal
static
readonly
UriHeaderParser
RelativeOrAbsoluteUriParser
=
new
UriHeaderParser
(
UriKind
.RelativeOrAbsolute);
11
12
private
UriHeaderParser
(
UriKind
uriKind)
13
: base(supportsMultipleValues: false)
14
{
15
_uriKind
= uriKind;
16
}
17
18
public
override
bool
TryParseValue
([NotNullWhen(
true
)]
string
value
,
object
storeValue, ref
int
index
, [NotNullWhen(
true
)] out
object
parsedValue)
19
{
20
parsedValue =
null
;
21
if
(
string
.IsNullOrEmpty(
value
) ||
index
==
value
.Length)
22
{
23
return
false
;
24
}
25
string
text
=
value
;
26
if
(
index
> 0)
27
{
28
text
=
value
.Substring(
index
);
29
}
30
if
(!
Uri
.
TryCreate
(
text
,
_uriKind
, out
Uri
result))
31
{
32
text
=
DecodeUtf8FromString
(
text
);
33
if
(!
Uri
.
TryCreate
(
text
,
_uriKind
, out result))
34
{
35
return
false
;
36
}
37
}
38
index
=
value
.Length;
39
parsedValue = result;
40
return
true
;
41
}
42
43
internal
static
string
DecodeUtf8FromString
(
string
input
)
44
{
45
if
(
string
.IsNullOrWhiteSpace(
input
))
46
{
47
return
input
;
48
}
49
bool
flag =
false
;
50
for
(
int
i = 0; i <
input
.Length; i++)
51
{
52
if
(
input
[i] >
'ÿ'
)
53
{
54
return
input
;
55
}
56
if
(
input
[i] >
'\u007f'
)
57
{
58
flag =
true
;
59
break
;
60
}
61
}
62
if
(flag)
63
{
64
byte
[]
array
=
new
byte
[
input
.Length];
65
for
(
int
j = 0; j <
input
.Length; j++)
66
{
67
if
(
input
[j] >
'ÿ'
)
68
{
69
return
input
;
70
}
71
array
[j] = (byte)
input
[j];
72
}
73
try
74
{
75
Encoding
encoding =
Encoding
.
GetEncoding
(
"utf-8"
,
EncoderFallback
.
ExceptionFallback
,
DecoderFallback
.
ExceptionFallback
);
76
return
encoding.
GetString
(
array
, 0,
array
.Length);
77
}
78
catch
(
ArgumentException
)
79
{
80
}
81
}
82
return
input
;
83
}
84
85
public
override
string
ToString
(
object
value
)
86
{
87
Uri
uri = (
Uri
)
value
;
88
if
(uri.
IsAbsoluteUri
)
89
{
90
return
uri.
AbsoluteUri
;
91
}
92
return
uri.
GetComponents
(
UriComponents
.SerializationInfoString,
UriFormat
.UriEscaped);
93
}
94
}
System.ArgumentException
Definition
ArgumentException.cs:9
System.Net.Http.Headers.HttpHeaderParser
Definition
HttpHeaderParser.cs:8
System.Net.Http.Headers.UriHeaderParser.UriHeaderParser
UriHeaderParser(UriKind uriKind)
Definition
UriHeaderParser.cs:12
System.Net.Http.Headers.UriHeaderParser.TryParseValue
override bool TryParseValue([NotNullWhen(true)] string value, object storeValue, ref int index, [NotNullWhen(true)] out object parsedValue)
Definition
UriHeaderParser.cs:18
System.Net.Http.Headers.UriHeaderParser.ToString
override string ToString(object value)
Definition
UriHeaderParser.cs:85
System.Net.Http.Headers.UriHeaderParser.RelativeOrAbsoluteUriParser
static readonly UriHeaderParser RelativeOrAbsoluteUriParser
Definition
UriHeaderParser.cs:10
System.Net.Http.Headers.UriHeaderParser._uriKind
readonly UriKind _uriKind
Definition
UriHeaderParser.cs:8
System.Net.Http.Headers.UriHeaderParser.DecodeUtf8FromString
static string DecodeUtf8FromString(string input)
Definition
UriHeaderParser.cs:43
System.Net.Http.Headers.UriHeaderParser
Definition
UriHeaderParser.cs:7
System.Text.DecoderFallback.ExceptionFallback
static DecoderFallback ExceptionFallback
Definition
DecoderFallback.cs:7
System.Text.DecoderFallback
Definition
DecoderFallback.cs:4
System.Text.EncoderFallback.ExceptionFallback
static EncoderFallback ExceptionFallback
Definition
EncoderFallback.cs:7
System.Text.EncoderFallback
Definition
EncoderFallback.cs:4
System.Text.Encoding.GetEncoding
static Encoding GetEncoding(int codepage)
Definition
Encoding.cs:593
System.Text.Encoding.GetString
unsafe string GetString(byte *bytes, int byteCount)
Definition
Encoding.cs:973
System.Text.Encoding
Definition
Encoding.cs:15
System.Uri.TryCreate
static bool TryCreate([NotNullWhen(true)] string? uriString, UriKind uriKind, [NotNullWhen(true)] out Uri? result)
Definition
Uri.cs:3793
System.Uri.AbsoluteUri
string AbsoluteUri
Definition
Uri.cs:266
System.Uri.IsAbsoluteUri
bool IsAbsoluteUri
Definition
Uri.cs:572
System.Uri.GetComponents
string GetComponents(UriComponents components, UriFormat format)
Definition
Uri.cs:3883
System.Uri
Definition
Uri.cs:16
System.Diagnostics.CodeAnalysis
Definition
AllowNullAttribute.cs:1
System.Net.Http.Headers
Definition
AltSvcHeaderParser.cs:4
System.Text
Definition
ConsoleEncoding.cs:1
System.UriKind
UriKind
Definition
UriKind.cs:4
System.ExceptionArgument.text
@ text
System.ExceptionArgument.value
@ value
System.ExceptionArgument.index
@ index
System.ExceptionArgument.input
@ input
System.ExceptionArgument.array
@ array
System.UriFormat
UriFormat
Definition
UriFormat.cs:4
System.UriComponents
UriComponents
Definition
UriComponents.cs:5
source
System.Net.Http
System.Net.Http.Headers
UriHeaderParser.cs
Generated by
1.10.0