ln.http.resources/ResourceApplication.cs
Harald Wolff e94811994f WIP
2019-04-05 00:59:02 +02:00

39 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
namespace ln.http.resources
{
public class ResourceApplication : HttpApplication
{
public Resource RootResource { get; set; }
public ResourceApplication()
{
RootResource = new BaseResource("");
}
public override HttpResponse GetResponse(HttpRequest httpRequest)
{
/* TODO: Implement Authentication here... */
Resource currentResource = RootResource;
Queue<String> pathStack = new Queue<String>(httpRequest.URI.AbsolutePath.Split(new String[] { "/" }, StringSplitOptions.RemoveEmptyEntries));
while ((pathStack.Count > 0) && (!currentResource.HandlesDispatching))
{
String next = pathStack.Dequeue();
if (!currentResource.Contains(next))
throw new KeyNotFoundException();
currentResource = currentResource.GetResource(next);
/* TODO: Implement Authorization hook here... */
}
return currentResource.GetResponse(httpRequest,pathStack);
}
}
}