aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Net/RequestContext.cs
blob: 531faab8405e9bbac95a2a61c64bd7cecc382f27 (plain)
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
using System.Linq;
using System.Net;
using System.IO.Compression;

namespace MediaBrowser.Controller.Net
{
    public class RequestContext
    {
        public HttpListenerRequest Request { get; private set; }
        public HttpListenerResponse Response { get; private set; }

        public RequestContext(HttpListenerContext context)
        {
            Response = context.Response;
            Request = context.Request;
        }

        public void Respond(Response response)
        {
            Response.AddHeader("Access-Control-Allow-Origin", "*");

            foreach (var header in response.Headers)
            {
                Response.AddHeader(header.Key, header.Value);
            }

            Response.ContentType = response.ContentType;
            Response.StatusCode = response.StatusCode;

            Response.SendChunked = true;

            GZipStream gzipStream = new GZipStream(Response.OutputStream, CompressionMode.Compress, false);

            response.WriteStream(Response.OutputStream);
        }
    }
}