/
RazorHandler.cs
56 lines (46 loc) · 1.61 KB
/
RazorHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System.Net;
using ServiceStack.Common.Web;
using ServiceStack.ServiceHost;
using ServiceStack.Text;
using ServiceStack.WebHost.Endpoints.Support;
namespace ServiceStack.Razor
{
public class RazorHandler : EndpointHandlerBase
{
public RazorFormat RazorFormat { get; set; }
public ViewPage RazorPage { get; set; }
public string PathInfo { get; set; }
public string FilePath { get; set; }
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
httpRes.ContentType = ContentType.Html;
var contentPage = RazorPage;
if (contentPage == null)
{
var pageFilePath = this.FilePath.WithoutExtension();
contentPage = RazorFormat.GetContentPage(pageFilePath);
}
if (contentPage == null)
{
httpRes.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
RazorFormat.ReloadModifiedPageAndTemplates(contentPage);
if (httpReq.DidReturn304NotModified(contentPage.GetLastModified(), httpRes))
return;
var modelType = RazorPage.GetRazorTemplate().ModelType;
var model = modelType == typeof(DynamicRequestObject)
? null
: DeserializeHttpRequest(modelType, httpReq, httpReq.ContentType);
RazorFormat.ProcessRazorPage(httpReq, contentPage, model, httpRes);
}
public override object CreateRequest(IHttpRequest request, string operationName)
{
return null;
}
public override object GetResponse(IHttpRequest httpReq, IHttpResponse httpRes, object request)
{
return null;
}
}
}