Last change
on this file since 325 was 325, checked in by alloc, 7 years ago |
Code style cleanup (mostly whitespace changes, enforcing braces, using cleanup)
|
File size:
1.0 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 static void WriteJSON (HttpListenerResponse resp, JSONNode root) {
|
---|
8 | StringBuilder sb = new StringBuilder ();
|
---|
9 | root.ToString (sb);
|
---|
10 | byte[] buf = Encoding.UTF8.GetBytes (sb.ToString ());
|
---|
11 | resp.ContentLength64 = buf.Length;
|
---|
12 | resp.ContentType = "application/json";
|
---|
13 | resp.ContentEncoding = Encoding.UTF8;
|
---|
14 | resp.OutputStream.Write (buf, 0, buf.Length);
|
---|
15 | }
|
---|
16 |
|
---|
17 | public static void WriteText (HttpListenerResponse _resp, string _text) {
|
---|
18 | byte[] buf = Encoding.UTF8.GetBytes (_text);
|
---|
19 | _resp.ContentLength64 = buf.Length;
|
---|
20 | _resp.ContentType = "text/plain";
|
---|
21 | _resp.ContentEncoding = Encoding.UTF8;
|
---|
22 | _resp.OutputStream.Write (buf, 0, buf.Length);
|
---|
23 | }
|
---|
24 |
|
---|
25 | public abstract void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user,
|
---|
26 | int permissionLevel);
|
---|
27 |
|
---|
28 | public virtual int DefaultPermissionLevel () {
|
---|
29 | return 0;
|
---|
30 | }
|
---|
31 | }
|
---|
32 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.