Changeset 387 for binary-improvements2/MapRendering/Web/SSE/SseHandler.cs
- Timestamp:
- Aug 6, 2022, 11:32:32 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.