forked from bonesoul/uhttpsharp
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathQueryStringHttpHeaders.cs
More file actions
63 lines (55 loc) · 1.86 KB
/
QueryStringHttpHeaders.cs
File metadata and controls
63 lines (55 loc) · 1.86 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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace uhttpsharp.Headers
{
[DebuggerDisplay("{Count} Query String Headers")]
[DebuggerTypeProxy(typeof(HttpHeadersDebuggerProxy))]
internal class QueryStringHttpHeaders : IHttpHeaders
{
private readonly HttpHeaders _child;
private static readonly char[] Seperators = {'&', '='};
private readonly int _count;
public QueryStringHttpHeaders(string query)
{
var splittedKeyValues = query.Split(Seperators, StringSplitOptions.RemoveEmptyEntries);
var values = new Dictionary<string, string>(splittedKeyValues.Length / 2, StringComparer.InvariantCultureIgnoreCase);
for (int i = 0; i < splittedKeyValues.Length; i += 2)
{
var key = Uri.UnescapeDataString(splittedKeyValues[i]);
string value = null;
if (splittedKeyValues.Length > i + 1)
{
value = Uri.UnescapeDataString(splittedKeyValues[i + 1]).Replace('+', ' ');
}
values[key] = value;
}
_count = values.Count;
_child = new HttpHeaders(values);
}
public string GetByName(string name)
{
return _child.GetByName(name);
}
public bool TryGetByName(string name, out string value)
{
return _child.TryGetByName(name, out value);
}
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
{
return _child.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
internal int Count
{
get
{
return _count;
}
}
}
}