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
47 lines (37 loc) · 1.66 KB
/
QueryStringHttpHeaders.cs
File metadata and controls
47 lines (37 loc) · 1.66 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
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 static readonly char[] Seperators = {'&', '='};
private readonly HttpHeaders _child;
internal int Count { get; }
public QueryStringHttpHeaders(string query) {
var splittedKeyValues = query.Split(Seperators, StringSplitOptions.RemoveEmptyEntries);
var values = new Dictionary<string, string>(splittedKeyValues.Length / 2, StringComparer.InvariantCultureIgnoreCase);
for (var 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();
}
}
}