Changeset 460 for TFP-WebServer/WebServer/src/UrlHandlers/ApiHandler.cs
- Timestamp:
- Aug 11, 2023, 6:29:09 PM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TFP-WebServer/WebServer/src/UrlHandlers/ApiHandler.cs
r459 r460 53 53 private static readonly UnityEngine.Profiling.CustomSampler apiHandlerSampler = UnityEngine.Profiling.CustomSampler.Create ("API_Handler"); 54 54 55 private bool HandleCors (RequestContext _context) { 56 _context.Request.Headers.TryGetValue ("Origin", out string origin); 57 _context.Response.AddHeader ("Access-Control-Allow-Origin", origin ?? "*"); 58 59 if (_context.Method != ERequestMethod.OPTIONS) { 60 return false; 61 } 62 63 if (!_context.Request.Headers.TryGetValue ("Access-Control-Request-Method", out _)) { 64 return false; 65 } 66 67 _context.Response.AddHeader ("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE, OPTIONS, HEAD"); 68 _context.Response.AddHeader ("Access-Control-Allow-Headers", "X-SDTD-API-TOKENNAME, X-SDTD-API-SECRET"); 69 _context.Response.AddHeader ("Access-Control-Allow-Credentials", "true"); 70 return true; 71 } 72 55 73 public override void HandleRequest (RequestContext _context) { 56 74 … … 72 90 } 73 91 92 // CORS specific stuff 93 if (HandleCors (_context)) { 94 return; 95 } 96 // CORS end 97 74 98 _context.RequestPath = subPath; 75 99
Note:
See TracChangeset
for help on using the changeset viewer.