2020-01-13 08:43:24 +01:00
|
|
|
|
// /**
|
|
|
|
|
// * File: FileSystemRouter.cs
|
|
|
|
|
// * Author: haraldwolff
|
|
|
|
|
// *
|
|
|
|
|
// * This file and it's content is copyrighted by the Author and / or copyright holder.
|
|
|
|
|
// * Any use wihtout proper permission is illegal and may lead to legal actions.
|
|
|
|
|
// *
|
|
|
|
|
// *
|
|
|
|
|
// **/
|
|
|
|
|
using System.IO;
|
2020-02-04 08:59:58 +01:00
|
|
|
|
using ln.http.message;
|
2020-01-13 08:43:24 +01:00
|
|
|
|
namespace ln.http.router
|
|
|
|
|
{
|
|
|
|
|
public class FileRouter : IHttpRouter
|
|
|
|
|
{
|
|
|
|
|
public string FileName { get; set; }
|
|
|
|
|
|
|
|
|
|
public FileRouter(string filename)
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(filename))
|
|
|
|
|
throw new FileNotFoundException();
|
|
|
|
|
|
|
|
|
|
FileName = filename;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-03 17:13:31 +01:00
|
|
|
|
public HttpResponse Route(HttpRoutingContext routingContext, HttpRequest httpRequest)
|
2020-01-13 08:43:24 +01:00
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse = new HttpResponse(httpRequest, new FileStream(FileName, FileMode.Open));
|
|
|
|
|
httpResponse.SetHeader("content-type", MimeTypeMap.GetMimeType(Path.GetExtension(FileName)));
|
|
|
|
|
|
|
|
|
|
return httpResponse;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|