|
Last change
on this file since 329 was 326, checked in by alloc, 7 years ago |
|
More cleanup, allocation improvements
|
|
File size:
1.1 KB
|
| Rev | Line | |
|---|
| [230] | 1 | using System.Net;
|
|---|
| 2 | using System.Text;
|
|---|
| [325] | 3 | using AllocsFixes.JSON;
|
|---|
| [230] | 4 |
|
|---|
| [325] | 5 | namespace AllocsFixes.NetConnections.Servers.Web.API {
|
|---|
| 6 | public abstract class WebAPI {
|
|---|
| [326] | 7 | public readonly string Name;
|
|---|
| 8 |
|
|---|
| 9 | protected WebAPI () {
|
|---|
| 10 | Name = GetType ().Name;
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| [325] | 13 | public static void WriteJSON (HttpListenerResponse resp, JSONNode root) {
|
|---|
| [309] | 14 | StringBuilder sb = new StringBuilder ();
|
|---|
| 15 | root.ToString (sb);
|
|---|
| 16 | byte[] buf = Encoding.UTF8.GetBytes (sb.ToString ());
|
|---|
| [230] | 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 |
|
|---|
| [325] | 23 | public static void WriteText (HttpListenerResponse _resp, string _text) {
|
|---|
| [306] | 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 |
|
|---|
| [325] | 31 | public abstract void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user,
|
|---|
| 32 | int permissionLevel);
|
|---|
| [279] | 33 |
|
|---|
| 34 | public virtual int DefaultPermissionLevel () {
|
|---|
| 35 | return 0;
|
|---|
| 36 | }
|
|---|
| [230] | 37 | }
|
|---|
| [325] | 38 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.