Ignore:
Timestamp:
Aug 6, 2022, 11:32:32 PM (2 years ago)
Author:
alloc
Message:

Big refactoring in Web to pass around a Context instead of a bunch of individual arguments all the time

File:
1 moved

Legend:

Unmodified
Added
Removed
  • binary-improvements2/MapRendering/Web/API/AbsWebAPI.cs

    r386 r387  
    1 using System.Text;
    2 using AllocsFixes.JSON;
    3 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;
    4 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;
    5 
    61namespace AllocsFixes.NetConnections.Servers.Web.API {
    7         public abstract class WebAPI {
     2        public abstract class AbsWebAPI {
    83                public readonly string Name;
    94
    10                 protected WebAPI (string _name = null) {
     5                protected AbsWebAPI (string _name = null) {
    116                        Name = _name ?? GetType ().Name;
    127                }
    138
    14 #if ENABLE_PROFILER
    15                 private static readonly UnityEngine.Profiling.CustomSampler jsonSerializeSampler = UnityEngine.Profiling.CustomSampler.Create ("JSON_Serialize");
    16                 private static readonly UnityEngine.Profiling.CustomSampler netWriteSampler = UnityEngine.Profiling.CustomSampler.Create ("JSON_Write");
    17 #endif
    18 
    19                 public static void WriteJSON (HttpListenerResponse _resp, JSONNode _root) {
    20 #if ENABLE_PROFILER
    21                         jsonSerializeSampler.Begin ();
    22 #endif
    23                         StringBuilder sb = new StringBuilder ();
    24                         _root.ToString (sb);
    25 #if ENABLE_PROFILER
    26                         jsonSerializeSampler.End ();
    27                         netWriteSampler.Begin ();
    28 #endif
    29                         byte[] buf = Encoding.UTF8.GetBytes (sb.ToString ());
    30                         _resp.ContentLength64 = buf.Length;
    31                         _resp.ContentType = "application/json";
    32                         _resp.ContentEncoding = Encoding.UTF8;
    33                         _resp.OutputStream.Write (buf, 0, buf.Length);
    34 #if ENABLE_PROFILER
    35                         netWriteSampler.End ();
    36 #endif
    37                 }
    38 
    39                 public static void WriteText (HttpListenerResponse _resp, string _text) {
    40                         byte[] buf = Encoding.UTF8.GetBytes (_text);
    41                         _resp.ContentLength64 = buf.Length;
    42                         _resp.ContentType = "text/plain";
    43                         _resp.ContentEncoding = Encoding.UTF8;
    44                         _resp.OutputStream.Write (buf, 0, buf.Length);
    45                 }
    46 
    47                 public abstract void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp,
    48                         WebConnection _user, int _permissionLevel);
     9                public abstract void HandleRequest (RequestContext _context);
    4910
    5011                public virtual int DefaultPermissionLevel () {
Note: See TracChangeset for help on using the changeset viewer.