This repository was archived by the owner on Jul 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOwinResponseWrapper.cs
More file actions
176 lines (139 loc) · 3.17 KB
/
OwinResponseWrapper.cs
File metadata and controls
176 lines (139 loc) · 3.17 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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System;
using Funq;
using SimpleStack.Interfaces;
using SimpleStack.Logging;
using System.Reflection;
using System.IO;
using System.Collections.Generic;
using SimpleStack.Enums;
using System.Linq;
using Microsoft.Owin;
using System.Text;
using SimpleStack.Extensions;
namespace SimpleStack
{
class OwinResponseWrapper : IHttpResponse
{
private IOwinResponse _response;
private bool _isClosed = false;
public OwinResponseWrapper(IOwinResponse response)
{
if (response == null)
throw new ArgumentNullException ("response");
this._response = response;
}
#region IHttpResponse implementation
public void AddHeader (string name, string value)
{
_response.Headers.Add(name, new string[]{value});
}
public void Redirect (string url)
{
_response.Redirect (url);
}
public void Write (string text)
{
_response.Write (text);
}
public void Close ()
{
_isClosed = true;
}
public void End ()
{
_isClosed = true;
}
public void Flush ()
{
}
public void SetContentLength (long contentLength)
{
_response.ContentLength = contentLength;
}
public object OriginalResponse {
get {
return _response;
}
}
public int StatusCode {
get {
return _response.StatusCode;
}
set {
_response.StatusCode = value;
}
}
//TODO
public string StatusDescription {
get {
return StatusCode == 200 ? "Ok" : "Error";
}
set {
}
}
public string ContentType {
get {
return _response.ContentType;
}
set {
_response.ContentType = value;
}
}
public ICookies Cookies {
get {
return new CookiesCollections(_response.Cookies);
}
}
public Stream OutputStream {
get {
return _response.Body;
}
}
public bool IsClosed {
get {
return _isClosed;
}
}
#endregion
class CookiesCollections : ICookies
{
ResponseCookieCollection cookies;
public CookiesCollections(ResponseCookieCollection cookies)
{
if(cookies == null)
throw new ArgumentNullException("cookies");
this.cookies = cookies;
}
#region ICookies implementation
public void DeleteCookie(string cookieName)
{
cookies.Delete(cookieName);
}
public void AddCookie(System.Net.Cookie cookie)
{
CookieOptions options = new CookieOptions();
options.Domain = cookie.Domain;
options.Expires = cookie.Expires;
options.HttpOnly = cookie.HttpOnly;
options.Path = cookie.Path;
options.Secure = cookie.Secure;
cookies.Append(cookie.Name, cookie.Value,options);
}
public void AddPermanentCookie(string cookieName, string cookieValue, bool? secureOnly = default(bool?))
{
CookieOptions options = new CookieOptions();
options.Expires = DateTime.MaxValue;
options.Secure = secureOnly.HasValue ? secureOnly.Value : false;;
cookies.Append(cookieName, cookieValue,options);
}
public void AddSessionCookie(string cookieName, string cookieValue, bool? secureOnly = default(bool?))
{
CookieOptions options = new CookieOptions();
options.Expires = null;
options.Secure = secureOnly.HasValue ? secureOnly.Value : false;
cookies.Append(cookieName, cookieValue,options);
}
#endregion
}
}
}