Changeset 199 for binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/StaticHandler.cs
- Timestamp:
- Sep 22, 2014, 11:15:14 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/StaticHandler.cs
r189 r199 11 11 private string datapath; 12 12 private string staticPart; 13 private boolcache;13 private AllocsFixes.FileCache.AbstractCache cache; 14 14 private bool logMissingFiles; 15 private Dictionary<string, byte[]> fileCache = new Dictionary<string, byte[]> ();16 15 17 public StaticHandler (string staticPart, string filePath, boolcache, bool logMissingFiles)16 public StaticHandler (string staticPart, string filePath, AllocsFixes.FileCache.AbstractCache cache, bool logMissingFiles) 18 17 { 19 18 this.staticPart = staticPart; … … 28 27 string fn = req.Url.AbsolutePath.Remove (0, staticPart.Length); 29 28 30 byte[] content; 31 if (cache) { 32 lock (fileCache) { 33 if (!fileCache.ContainsKey (fn)) { 34 if (!File.Exists (datapath + "/" + fn)) { 35 throw new FileNotFoundException (); 36 } 37 38 fileCache.Add (fn, File.ReadAllBytes (datapath + "/" + fn)); 39 } 40 41 content = fileCache [fn]; 42 } 29 byte[] content = cache.GetFileContent (datapath + "/" + fn); 30 if (content != null) { 31 resp.ContentType = MimeType.GetMimeType (Path.GetExtension (fn)); 32 resp.ContentLength64 = content.Length; 33 resp.OutputStream.Write (content, 0, content.Length); 43 34 } else { 44 if (!File.Exists (datapath + "/" + fn)) { 45 throw new FileNotFoundException (); 46 } 47 48 content = File.ReadAllBytes (datapath + "/" + fn); 35 resp.StatusCode = (int)HttpStatusCode.NotFound; 36 if (logMissingFiles) 37 Log.Out ("Web:Static:FileNotFound: \"" + req.Url.AbsolutePath + "\" @ \"" + datapath + "/" + req.Url.AbsolutePath.Remove (0, staticPart.Length) + "\""); 38 return; 49 39 } 50 51 resp.ContentType = MimeType.GetMimeType (Path.GetExtension (fn));52 resp.ContentLength64 = content.Length;53 resp.OutputStream.Write (content, 0, content.Length);54 } catch (FileNotFoundException) {55 resp.StatusCode = (int)HttpStatusCode.NotFound;56 if (logMissingFiles)57 Log.Out ("Web:Static:FileNotFound: \"" + req.Url.AbsolutePath + "\" @ \"" + datapath + "/" + req.Url.AbsolutePath.Remove (0, staticPart.Length) + "\"");58 return;59 40 } catch (Exception e) { 60 41 Log.Out ("Error in StaticHandler.HandleRequest: " + e);
Note:
See TracChangeset
for help on using the changeset viewer.