forked from Code-Sharp/uHttpSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryStringHttpHeaders.cs
More file actions
59 lines (49 loc) · 1.78 KB
/
Copy pathQueryStringHttpHeaders.cs
File metadata and controls
59 lines (49 loc) · 1.78 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
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[] Separators = { '&', '=' };
public QueryStringHttpHeaders(string query)
{
string[] splitKeyValues = query.Split(Separators, StringSplitOptions.RemoveEmptyEntries);
Dictionary<string, string> values = new Dictionary<string, string>(splitKeyValues.Length / 2,
StringComparer.InvariantCultureIgnoreCase);
for (int i = 0; i < splitKeyValues.Length; i += 2)
{
string key = Uri.UnescapeDataString(splitKeyValues[i]);
string value = null;
if (splitKeyValues.Length > i + 1)
{
value = Uri.UnescapeDataString(splitKeyValues[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; }
}
}