Last change
on this file since 326 was
326,
checked in by alloc, 5 years ago
|
More cleanup, allocation improvements
|
File size:
1.1 KB
|
Line | |
---|
1 | using System.Net; |
---|
2 | using System.Text; |
---|
3 | using AllocsFixes.JSON; |
---|
4 | |
---|
5 | namespace AllocsFixes.NetConnections.Servers.Web.API { |
---|
6 | public abstract class WebAPI { |
---|
7 | public readonly string Name; |
---|
8 | |
---|
9 | protected WebAPI () { |
---|
10 | Name = GetType ().Name; |
---|
11 | } |
---|
12 | |
---|
13 | public static void WriteJSON (HttpListenerResponse resp, JSONNode root) { |
---|
14 | StringBuilder sb = new StringBuilder (); |
---|
15 | root.ToString (sb); |
---|
16 | byte[] buf = Encoding.UTF8.GetBytes (sb.ToString ()); |
---|
17 | resp.ContentLength64 = buf.Length; |
---|
18 | resp.ContentType = "application/json"; |
---|
19 | resp.ContentEncoding = Encoding.UTF8; |
---|
20 | resp.OutputStream.Write (buf, 0, buf.Length); |
---|
21 | } |
---|
22 | |
---|
23 | public static void WriteText (HttpListenerResponse _resp, string _text) { |
---|
24 | byte[] buf = Encoding.UTF8.GetBytes (_text); |
---|
25 | _resp.ContentLength64 = buf.Length; |
---|
26 | _resp.ContentType = "text/plain"; |
---|
27 | _resp.ContentEncoding = Encoding.UTF8; |
---|
28 | _resp.OutputStream.Write (buf, 0, buf.Length); |
---|
29 | } |
---|
30 | |
---|
31 | public abstract void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, |
---|
32 | int permissionLevel); |
---|
33 | |
---|
34 | public virtual int DefaultPermissionLevel () { |
---|
35 | return 0; |
---|
36 | } |
---|
37 | } |
---|
38 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.