-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathContent.cs
More file actions
63 lines (59 loc) · 1.8 KB
/
Content.cs
File metadata and controls
63 lines (59 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
namespace Https
{
class Content
{
public ContentLocation ContentLocation { get; }
public string Property { get; }
public string Value { get; }
Content(ContentLocation contentLocation, string property, string value)
{
ContentLocation = contentLocation;
Property = property;
Value = value;
}
public static bool TryParse(string s, out Content content)
{
var equalsIndex = s.IndexOf('=');
var colonIndex = s.IndexOf(':');
if (equalsIndex == -1 && colonIndex == -1)
{
content = default;
return false;
}
var contentType = default(ContentLocation);
var index = default(int);
if (equalsIndex > -1 && colonIndex > -1)
{
if (equalsIndex < colonIndex)
{
contentType = ContentLocation.Body;
index = equalsIndex;
}
else
{
contentType = ContentLocation.Header;
index = colonIndex;
}
}
else if (equalsIndex > -1)
{
contentType = ContentLocation.Body;
index = equalsIndex;
}
else
{
contentType = ContentLocation.Header;
index = colonIndex;
}
var property = s.Substring(0, index);
if (property.Length == 0)
{
content = default;
return false;
}
var value = s.Substring(index + 1);
content = new Content(contentType, property, value);
return true;
}
}
}