Changeset 387 for binary-improvements2/MapRendering/Web/Web.cs
- Timestamp:
- Aug 6, 2022, 11:32:32 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/MapRendering/Web/Web.cs
r384 r387 6 6 using HttpStatusCode = System.Net.HttpStatusCode; 7 7 using IPEndPoint = System.Net.IPEndPoint; 8 using System.Text;9 8 using System.Threading; 10 9 using AllocsFixes.FileCache; … … 226 225 return; 227 226 } 228 229 ApplyPathHandler (requestPath, request, response, conn, permissionLevel); 227 228 RequestContext context = new RequestContext (requestPath, request, response, conn, permissionLevel); 229 230 ApplyPathHandler (context); 230 231 231 232 } catch (IOException e) { … … 252 253 } 253 254 254 public void ApplyPathHandler (string _requestPath, HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _con, 255 int _permissionLevel) { 255 public void ApplyPathHandler (RequestContext _context) { 256 256 for (int i = handlers.Count - 1; i >= 0; i--) { 257 257 AbsHandler handler = handlers [i]; 258 258 259 if (_ requestPath.StartsWith (handler.UrlBasePath)) {260 if (!handler.IsAuthorizedForHandler (_con , _permissionLevel)) {261 _ resp.StatusCode = (int)HttpStatusCode.Forbidden;262 if (_con != null) {259 if (_context.RequestPath.StartsWith (handler.UrlBasePath)) { 260 if (!handler.IsAuthorizedForHandler (_context.Connection, _context.PermissionLevel)) { 261 _context.Response.StatusCode = (int)HttpStatusCode.Forbidden; 262 if (_context.Connection != null) { 263 263 //Log.Out ("Web.HandleRequest: user '{0}' not allowed to access '{1}'", _con.SteamID, handler.ModuleName); 264 264 } … … 267 267 handlerSampler.Begin (); 268 268 #endif 269 handler.HandleRequest (_ requestPath, _req, _resp, _con, _permissionLevel);269 handler.HandleRequest (_context); 270 270 #if ENABLE_PROFILER 271 271 handlerSampler.End (); … … 279 279 // Not really relevant for non-debugging purposes: 280 280 //Log.Out ("Error in Web.HandleRequest(): No handler found for path \"" + _requestPath + "\""); 281 _ resp.StatusCode = (int) HttpStatusCode.NotFound;281 _context.Response.StatusCode = (int) HttpStatusCode.NotFound; 282 282 } 283 283 … … 314 314 return guestPermissionLevel; 315 315 } 316 317 public static void SetResponseTextContent (HttpListenerResponse _resp, string _text) {318 byte[] buf = Encoding.UTF8.GetBytes (_text);319 _resp.ContentLength64 = buf.Length;320 _resp.ContentType = "text/html";321 _resp.ContentEncoding = Encoding.UTF8;322 _resp.OutputStream.Write (buf, 0, buf.Length);323 }324 316 } 325 317 }
Note:
See TracChangeset
for help on using the changeset viewer.