Changeset 387 for binary-improvements2/MapRendering/Web/SSE
- Timestamp:
- Aug 6, 2022, 11:32:32 PM (3 years ago)
- Location:
- binary-improvements2/MapRendering/Web/SSE
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/MapRendering/Web/SSE/EventLog.cs
r382 r387 10 10 11 11 private void LogCallback (string _formattedMsg, string _plainMsg, string _trace, LogType _type, DateTime _timestamp, long _uptime) { 12 string date = $"{_timestamp.Year:0000}-{_timestamp.Month:00}-{_timestamp.Day:00}";13 string time = $"{_timestamp.Hour:00}:{_timestamp.Minute:00}:{_timestamp.Second:00}";14 12 string isotime = _timestamp.ToString ("o"); 15 13 string uptime = _uptime.ToString (); … … 20 18 data.Add ("type", new JSONString (_type.ToStringCached ())); 21 19 data.Add ("trace", new JSONString (_trace)); 22 data.Add ("date", new JSONString (date));23 data.Add ("time", new JSONString (time));24 20 data.Add ("isotime", new JSONString (isotime)); 25 21 data.Add ("uptime", new JSONString (uptime)); -
binary-improvements2/MapRendering/Web/SSE/SseHandler.cs
r382 r387 5 5 using System.Threading; 6 6 using AllocsFixes.NetConnections.Servers.Web.Handlers; 7 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;8 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;9 7 10 8 // Implemented following HTML spec … … 52 50 } 53 51 54 public override void HandleRequest (string _requestPath, HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _con, 55 int _permissionLevel) { 56 string eventName = _requestPath.Remove (0, urlBasePath.Length); 52 public override void HandleRequest (RequestContext _context) { 53 string eventName = _context.RequestPath.Remove (0, urlBasePath.Length); 57 54 58 55 if (!events.TryGetValue (eventName, out EventBase eventInstance)) { 59 56 Log.Out ($"Error in {nameof (SseHandler)}.HandleRequest(): No handler found for event \"{eventName}\""); 60 _ resp.StatusCode = (int)HttpStatusCode.NotFound;57 _context.Response.StatusCode = (int)HttpStatusCode.NotFound; 61 58 return; 62 59 } 63 60 64 if (!IsAuthorizedForEvent (eventName, _ permissionLevel)) {65 _ resp.StatusCode = (int)HttpStatusCode.Forbidden;66 if (_con != null) {61 if (!IsAuthorizedForEvent (eventName, _context.PermissionLevel)) { 62 _context.Response.StatusCode = (int)HttpStatusCode.Forbidden; 63 if (_context.Connection != null) { 67 64 //Log.Out ($"{nameof(SseHandler)}: user '{user.SteamID}' not allowed to access '{eventName}'"); 68 65 } … … 72 69 73 70 try { 74 eventInstance.AddListener (_ resp);71 eventInstance.AddListener (_context.Response); 75 72 76 73 // Keep the request open 77 _ resp.SendChunked = true;74 _context.Response.SendChunked = true; 78 75 79 _ resp.AddHeader ("Content-Type", "text/event-stream");80 _ resp.OutputStream.Flush ();76 _context.Response.AddHeader ("Content-Type", "text/event-stream"); 77 _context.Response.OutputStream.Flush (); 81 78 } catch (Exception e) { 82 79 Log.Error ($"Error in {nameof (SseHandler)}.HandleRequest(): Handler {eventInstance.Name} threw an exception:"); 83 80 Log.Exception (e); 84 _ resp.StatusCode = (int)HttpStatusCode.InternalServerError;81 _context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; 85 82 } 86 83 }
Note:
See TracChangeset
for help on using the changeset viewer.