/
OwinRequest.cs
91 lines (77 loc) · 2.12 KB
/
OwinRequest.cs
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Security.Principal;
using System.Threading;
using Gate;
using SignalR.Hosting.Common;
namespace SignalR.Hosting.Owin
{
public class OwinRequest : IRequest
{
private readonly CookieManager _cookies;
public OwinRequest(IDictionary<string, object> environment, string body)
{
var env = new Gate.Environment(environment);
var headers = env.Headers;
Url = BuildUrl(env);
Headers = new NameValueCollection();
foreach (var pair in headers)
{
foreach (var value in pair.Value)
{
Headers.Add(pair.Key, value);
}
}
_cookies = new CookieManager();
QueryString = HttpUtility.ParseDelimited(env.QueryString);
Form = HttpUtility.ParseDelimited(body);
}
public IRequestCookieCollection Cookies
{
get
{
return _cookies;
}
}
public NameValueCollection Form
{
get;
private set;
}
public NameValueCollection Headers
{
get;
private set;
}
public NameValueCollection QueryString
{
get;
private set;
}
public Uri Url
{
get;
private set;
}
public IPrincipal User
{
get
{
return Thread.CurrentPrincipal;
}
}
/// <summary>
/// Based on http://owin.org/spec/owin-1.0.0draft5.html#URIReconstruction
/// </summary>
private Uri BuildUrl(Gate.Environment env)
{
string url = env.Scheme + "://" + env.Headers.GetHeader("Host") + env.PathBase + env.Path;
if (!String.IsNullOrEmpty(env.QueryString))
{
url += "?" + env.QueryString;
}
return new Uri(url);
}
}
}