// /** // * 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; using ln.http.message; 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; } public HttpResponse Route(HttpRoutingContext routingContext, HttpRequest httpRequest) { HttpResponse httpResponse = new HttpResponse(httpRequest, new FileStream(FileName, FileMode.Open)); httpResponse.SetHeader("content-type", MimeTypeMap.GetMimeType(Path.GetExtension(FileName))); return httpResponse; } } }