forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceStackHost.Runtime.cs
More file actions
156 lines (138 loc) · 5.78 KB
/
Copy pathServiceStackHost.Runtime.cs
File metadata and controls
156 lines (138 loc) · 5.78 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Copyright (c) Service Stack LLC. All Rights Reserved.
// License: https://raw.github.com/ServiceStack/ServiceStack/master/license.txt
using System;
using System.Linq;
using ServiceStack.Metadata;
using ServiceStack.MiniProfiler;
using ServiceStack.Support.WebHost;
using ServiceStack.Web;
namespace ServiceStack
{
public abstract partial class ServiceStackHost
{
/// <summary>
/// Applies the raw request filters. Returns whether or not the request has been handled
/// and no more processing should be done.
/// </summary>
/// <returns></returns>
public bool ApplyPreRequestFilters(IHttpRequest httpReq, IHttpResponse httpRes)
{
foreach (var requestFilter in PreRequestFilters)
{
requestFilter(httpReq, httpRes);
if (httpRes.IsClosed) break;
}
return httpRes.IsClosed;
}
/// <summary>
/// Applies the request filters. Returns whether or not the request has been handled
/// and no more processing should be done.
/// </summary>
/// <returns></returns>
public bool ApplyRequestFilters(IHttpRequest httpReq, IHttpResponse httpRes, object requestDto)
{
httpReq.ThrowIfNull("httpReq");
httpRes.ThrowIfNull("httpRes");
using (Profiler.Current.Step("Executing Request Filters"))
{
//Exec all RequestFilter attributes with Priority < 0
var attributes = FilterAttributeCache.GetRequestFilterAttributes(requestDto.GetType());
var i = 0;
for (; i < attributes.Length && attributes[i].Priority < 0; i++)
{
var attribute = attributes[i];
Container.AutoWire(attribute);
attribute.RequestFilter(httpReq, httpRes, requestDto);
Release(attribute);
if (httpRes.IsClosed) return httpRes.IsClosed;
}
//Exec global filters
foreach (var requestFilter in GlobalRequestFilters)
{
requestFilter(httpReq, httpRes, requestDto);
if (httpRes.IsClosed) return httpRes.IsClosed;
}
//Exec remaining RequestFilter attributes with Priority >= 0
for (; i < attributes.Length; i++)
{
var attribute = attributes[i];
Container.AutoWire(attribute);
attribute.RequestFilter(httpReq, httpRes, requestDto);
Release(attribute);
if (httpRes.IsClosed) return httpRes.IsClosed;
}
return httpRes.IsClosed;
}
}
/// <summary>
/// Applies the response filters. Returns whether or not the request has been handled
/// and no more processing should be done.
/// </summary>
/// <returns></returns>
public bool ApplyResponseFilters(IHttpRequest httpReq, IHttpResponse httpRes, object response)
{
httpReq.ThrowIfNull("httpReq");
httpRes.ThrowIfNull("httpRes");
using (Profiler.Current.Step("Executing Response Filters"))
{
var responseDto = response.GetResponseDto();
var attributes = responseDto != null
? FilterAttributeCache.GetResponseFilterAttributes(responseDto.GetType())
: null;
//Exec all ResponseFilter attributes with Priority < 0
var i = 0;
if (attributes != null)
{
for (; i < attributes.Length && attributes[i].Priority < 0; i++)
{
var attribute = attributes[i];
Container.AutoWire(attribute);
attribute.ResponseFilter(httpReq, httpRes, response);
Release(attribute);
if (httpRes.IsClosed) return httpRes.IsClosed;
}
}
//Exec global filters
foreach (var responseFilter in GlobalResponseFilters)
{
responseFilter(httpReq, httpRes, response);
if (httpRes.IsClosed) return httpRes.IsClosed;
}
//Exec remaining RequestFilter attributes with Priority >= 0
if (attributes != null)
{
for (; i < attributes.Length; i++)
{
var attribute = attributes[i];
Container.AutoWire(attribute);
attribute.ResponseFilter(httpReq, httpRes, response);
Release(attribute);
if (httpRes.IsClosed) return httpRes.IsClosed;
}
}
return httpRes.IsClosed;
}
}
public MetadataPagesConfig MetadataPagesConfig
{
get
{
return new MetadataPagesConfig(
Metadata,
Config.ServiceEndpointsMetadataConfig,
Config.IgnoreFormatsInMetadata,
ContentTypes.ContentTypeFormats.Keys.ToList());
}
}
public virtual TimeSpan GetDefaultSessionExpiry()
{
var authFeature = GetPlugin<AuthFeature>();
if (authFeature != null)
return authFeature.GetDefaultSessionExpiry();
var sessionFeature = GetPlugin<SessionFeature>();
return sessionFeature != null
? sessionFeature.SessionExpiry
: SessionFeature.DefaultSessionExpiry;
}
}
}