Changeset 134 for binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/StaticHandler.cs
- Timestamp:
- Aug 27, 2014, 5:35:51 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/StaticHandler.cs
r133 r134 3 3 using System.IO; 4 4 using System.Net; 5 using System.Threading; 5 6 6 7 namespace AllocsFixes.NetConnections.Servers.Web … … 11 12 private string staticPart; 12 13 private bool cache; 14 private bool logMissingFiles; 13 15 private Dictionary<string, byte[]> fileCache = new Dictionary<string, byte[]> (); 14 16 15 public StaticHandler (string staticPart, string filePath, bool cache )17 public StaticHandler (string staticPart, string filePath, bool cache, bool logMissingFiles) 16 18 { 17 19 this.staticPart = staticPart; 18 20 this.datapath = filePath; 19 21 this.cache = cache; 22 this.logMissingFiles = logMissingFiles; 20 23 } 21 24 22 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp )25 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, HttpListenerBasicIdentity user) 23 26 { 24 27 try { … … 27 30 byte[] content; 28 31 if (cache) { 29 if (!fileCache.ContainsKey (fn)) { 30 if (!File.Exists (datapath + "/" + fn)) { 31 resp.StatusCode = (int)HttpStatusCode.NotFound; 32 return; 32 Monitor.Enter (fileCache); 33 try { 34 if (!fileCache.ContainsKey (fn)) { 35 if (!File.Exists (datapath + "/" + fn)) { 36 resp.StatusCode = (int)HttpStatusCode.NotFound; 37 if (logMissingFiles) 38 Log.Out ("Web:Static:FileNotFound: " + req.Url.AbsolutePath); 39 return; 40 } 41 42 fileCache.Add (fn, File.ReadAllBytes (datapath + "/" + fn)); 33 43 } 34 44 35 fileCache.Add (fn, File.ReadAllBytes (datapath + "/" + fn)); 45 content = fileCache [fn]; 46 } finally { 47 Monitor.Exit (fileCache); 36 48 } 37 38 content = fileCache [fn];39 49 } else { 40 50 if (!File.Exists (datapath + "/" + fn)) { 41 51 resp.StatusCode = (int)HttpStatusCode.NotFound; 52 if (logMissingFiles) 53 Log.Out ("Web:Static:FileNotFound: " + req.Url.AbsolutePath); 42 54 return; 43 55 }
Note:
See TracChangeset
for help on using the changeset viewer.