forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpResponseStreamWrapper.cs
More file actions
79 lines (62 loc) · 1.86 KB
/
HttpResponseStreamWrapper.cs
File metadata and controls
79 lines (62 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.Collections.Generic;
using System.IO;
using System.Text;
using ServiceStack.ServiceHost;
using ServiceStack.Common;
namespace ServiceStack.Common.Web
{
public class HttpResponseStreamWrapper : IHttpResponse
{
private static readonly UTF8Encoding UTF8EncodingWithoutBom = new UTF8Encoding(false);
public HttpResponseStreamWrapper(Stream stream)
{
this.OutputStream = stream;
this.Headers = new Dictionary<string, string>();
}
public Dictionary<string, string> Headers { get; set; }
public object OriginalResponse
{
get { return null; }
}
public int StatusCode { set; get; }
public string StatusDescription { set; get; }
public string ContentType { get; set; }
public bool KeepOpen { get; set; }
public ICookies Cookies { get; set; }
public void AddHeader(string name, string value)
{
this.Headers[name] = value;
}
public void Redirect(string url)
{
this.Headers[HttpHeaders.Location] = url;
}
public Stream OutputStream { get; private set; }
public void Write(string text)
{
var bytes = UTF8EncodingWithoutBom.GetBytes(text);
OutputStream.Write(bytes, 0, bytes.Length);
}
public void Close()
{
if (KeepOpen) return;
ForceClose();
}
public void ForceClose()
{
if (IsClosed) return;
OutputStream.Close();
IsClosed = true;
}
public void End()
{
Close();
}
public void Flush()
{
OutputStream.Flush();
}
public bool IsClosed { get; private set; }
public void SetContentLength(long contentLength) {}
}
}