forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRazorHandler.cs
More file actions
67 lines (56 loc) · 2.18 KB
/
Copy pathRazorHandler.cs
File metadata and controls
67 lines (56 loc) · 2.18 KB
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
57
58
59
60
61
62
63
64
65
66
67
using System.Net;
using ServiceStack.Common.Web;
using ServiceStack.ServiceHost;
using ServiceStack.WebHost.Endpoints.Extensions;
using ServiceStack.WebHost.Endpoints.Support;
namespace ServiceStack.Razor
{
public class RazorHandler : EndpointHandlerBase
{
public RazorFormat RazorFormat { get; set; }
public ViewPageRef RazorPage { get; set; }
public object Model { get; set; }
public string PathInfo { get; set; }
public RazorHandler(string pathInfo)
{
PathInfo = pathInfo;
}
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
httpRes.ContentType = ContentType.Html;
if (RazorFormat == null)
RazorFormat = RazorFormat.Instance;
var contentPage = RazorPage ?? RazorFormat.FindByPathInfo(PathInfo);
if (contentPage == null)
{
httpRes.StatusCode = (int)HttpStatusCode.NotFound;
httpRes.EndHttpRequest();
return;
}
if (RazorFormat.WatchForModifiedPages)
RazorFormat.ReloadIfNeeeded(contentPage);
//Add good caching support
//if (httpReq.DidReturn304NotModified(contentPage.GetLastModified(), httpRes))
// return;
var model = Model;
if (model == null)
httpReq.Items.TryGetValue("Model", out model);
if (model == null)
{
var modelType = RazorPage != null ? RazorPage.GetRazorTemplate().ModelType : null;
model = modelType == null || 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;
}
}
}