forked from JamesDunne/aardwolf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJsonResponse.cs
executable file
·38 lines (32 loc) · 1.06 KB
/
JsonResponse.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
#pragma warning disable 1998
namespace Aardwolf
{
public sealed class JsonResponse : StatusResponse, IHttpResponseAction
{
readonly object _value;
public JsonResponse(int statusCode, string statusDescription, object value)
: base(statusCode, statusDescription)
{
_value = value;
}
public override async Task Execute(IHttpRequestResponseContext context)
{
SetStatus(context);
context.Response.ContentType = "application/json; charset=utf-8";
//context.Response.ContentEncoding = UTF8.WithoutBOM;
using (context.Response.OutputStream)
{
var tw = new StreamWriter(context.Response.OutputStream, UTF8.WithoutBOM);
Json.Serializer.Serialize(tw, _value);
}
}
}
}