Last change
on this file since 447 was 420, checked in by alloc, 20 months ago |
A21 preparations.
NOT COMPATIBLE WITH A20 ANYMORE!
|
File size:
1.2 KB
|
Rev | Line | |
---|
[230] | 1 | using System.IO;
|
---|
| 2 | using System.Net;
|
---|
[420] | 3 | using Webserver.FileCache;
|
---|
[230] | 4 |
|
---|
[325] | 5 | namespace AllocsFixes.NetConnections.Servers.Web.Handlers {
|
---|
| 6 | public class StaticHandler : PathHandler {
|
---|
| 7 | private readonly AbstractCache cache;
|
---|
| 8 | private readonly string datapath;
|
---|
| 9 | private readonly bool logMissingFiles;
|
---|
[230] | 10 |
|
---|
[367] | 11 | public StaticHandler (string _filePath, AbstractCache _cache, bool _logMissingFiles,
|
---|
[351] | 12 | string _moduleName = null) : base (_moduleName) {
|
---|
| 13 | datapath = _filePath + (_filePath [_filePath.Length - 1] == '/' ? "" : "/");
|
---|
| 14 | cache = _cache;
|
---|
| 15 | logMissingFiles = _logMissingFiles;
|
---|
[230] | 16 | }
|
---|
| 17 |
|
---|
[351] | 18 | public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
|
---|
| 19 | int _permissionLevel) {
|
---|
[367] | 20 | string fn = _req.Url.AbsolutePath.Remove (0, urlBasePath.Length);
|
---|
[230] | 21 |
|
---|
[332] | 22 | byte[] content = cache.GetFileContent (datapath + fn);
|
---|
[251] | 23 |
|
---|
[230] | 24 | if (content != null) {
|
---|
[351] | 25 | _resp.ContentType = MimeType.GetMimeType (Path.GetExtension (fn));
|
---|
| 26 | _resp.ContentLength64 = content.Length;
|
---|
| 27 | _resp.OutputStream.Write (content, 0, content.Length);
|
---|
[230] | 28 | } else {
|
---|
[351] | 29 | _resp.StatusCode = (int) HttpStatusCode.NotFound;
|
---|
[325] | 30 | if (logMissingFiles) {
|
---|
[351] | 31 | Log.Out ("Web:Static:FileNotFound: \"" + _req.Url.AbsolutePath + "\" @ \"" + datapath + fn + "\"");
|
---|
[325] | 32 | }
|
---|
[230] | 33 | }
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
[325] | 36 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.