Permalink
Browse files

Change RawRequestFilters into PreRequestFilters, added them to all Se…

…rviceStack Request Handlers
  • Loading branch information...
mythz committed Sep 2, 2012
1 parent c2cbe9e commit c152b9683fe199e03755013eff4ba79dedad8c25
View
@@ -1,7 +1,10 @@
+MD latest\ServiceStack
+MD latest\ServiceStack.OrmLite
+
COPY ..\NuGet\ServiceStack\lib\net35\* latest\ServiceStack
COPY ..\NuGet\ServiceStack\lib\net40\* latest\ServiceStack
COPY ..\NuGet\ServiceStack.Common\lib\net35\* latest\ServiceStack
-COPY ..\NuGet\ServiceStack.Mvc\lib\net4\* latest\ServiceStack
+COPY ..\NuGet\ServiceStack.Mvc\lib\net40\* latest\ServiceStack
COPY ..\NuGet\ServiceStack.Plugins.ProtoBuf\lib\net35\* latest\ServiceStack
COPY ..\..\ServiceStack.Text\NuGet\lib\net35\* latest\ServiceStack
@@ -15,7 +15,7 @@ public class BasicAppHost : IAppHost
public BasicAppHost()
{
this.Container = new Container();
- this.RawRequestFilters = new List<Action<IHttpRequest, IHttpResponse>>();
+ this.PreRequestFilters = new List<Action<IHttpRequest, IHttpResponse>>();
this.RequestFilters = new List<Action<IHttpRequest, IHttpResponse, object>>();
this.ResponseFilters = new List<Action<IHttpRequest, IHttpResponse, object>>();
this.ViewEngines = new List<IViewEngine>();
@@ -46,7 +46,7 @@ public T TryResolve<T>()
public IContentTypeFilter ContentTypeFilters { get; set; }
- public List<Action<IHttpRequest, IHttpResponse>> RawRequestFilters { get; set; }
+ public List<Action<IHttpRequest, IHttpResponse>> PreRequestFilters { get; set; }
public List<Action<IHttpRequest, IHttpResponse, object>> RequestFilters { get; set; }
@@ -31,7 +31,7 @@ public TestAppHost(Funq.Container container, params Assembly[] serviceAssemblies
new ServiceManager(true, serviceAssemblies));
this.ContentTypeFilters = new HttpResponseFilter();
- this.RawRequestFilters = new List<Action<IHttpRequest, IHttpResponse>>();
+ this.PreRequestFilters = new List<Action<IHttpRequest, IHttpResponse>>();
this.RequestFilters = new List<Action<IHttpRequest, IHttpResponse, object>>();
this.ResponseFilters = new List<Action<IHttpRequest, IHttpResponse, object>>();
this.ViewEngines = new List<IViewEngine>();
@@ -60,7 +60,7 @@ public T TryResolve<T>()
public IContentTypeFilter ContentTypeFilters { get; set; }
- public List<Action<IHttpRequest, IHttpResponse>> RawRequestFilters { get; set; }
+ public List<Action<IHttpRequest, IHttpResponse>> PreRequestFilters { get; set; }
public List<Action<IHttpRequest, IHttpResponse, object>> RequestFilters { get; set; }
@@ -164,7 +164,7 @@ public IContentTypeFilter ContentTypeFilters
}
}
- public List<Action<IHttpRequest, IHttpResponse>> RawRequestFilters
+ public List<Action<IHttpRequest, IHttpResponse>> PreRequestFilters
{
get
{
@@ -231,7 +231,7 @@ public static EndpointHostConfig Config
/// and no more processing should be done.
/// </summary>
/// <returns></returns>
- public static bool ApplyRawRequestFilters(IHttpRequest httpReq, IHttpResponse httpRes)
+ public static bool ApplyPreRequestFilters(IHttpRequest httpReq, IHttpResponse httpRes)
{
foreach (var requestFilter in RawRequestFilters)
{
@@ -55,7 +55,9 @@ public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes,
{
try
{
- EndpointHost.Config.AssertFeatures(usesFeature);
+ if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes)) return;
+
+ EndpointHost.Config.AssertFeatures(usesFeature);
httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
var callback = httpReq.QueryString["callback"];
@@ -45,7 +45,7 @@ public interface IAppHost : IResolver
/// <summary>
/// Add Request Filters, to be applied before the dto is deserialized
/// </summary>
- List<Action<IHttpRequest, IHttpResponse>> RawRequestFilters { get; }
+ List<Action<IHttpRequest, IHttpResponse>> PreRequestFilters { get; }
/// <summary>
/// Add Request Filters
@@ -44,7 +44,7 @@ public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes,
var responseContentType = EndpointHost.Config.DefaultContentType;
try
{
- if (EndpointHost.ApplyRawRequestFilters(httpReq, httpRes)) return;
+ if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes)) return;
var restPath = GetRestPath(httpReq.HttpMethod, httpReq.PathInfo);
if (restPath == null)
@@ -354,7 +354,7 @@ public IContentTypeFilter ContentTypeFilters
}
}
- public List<Action<IHttpRequest, IHttpResponse>> RawRequestFilters
+ public List<Action<IHttpRequest, IHttpResponse>> PreRequestFilters
{
get
{
@@ -39,7 +39,7 @@ public Message Send(Message requestMsg)
public Message EmptyResponse(Message requestMsg, Type requestType)
{
var responseType = AssemblyUtils.FindType(requestType.FullName + "Response");
- var response = ReflectionExtensions.CreateInstance(responseType ?? typeof(object));
+ var response = (responseType ?? typeof(object)).CreateInstance();
return requestMsg.Headers.Action == null
? Message.CreateMessage(requestMsg.Version, null, response)
@@ -60,17 +60,20 @@ protected Message ExecuteMessage(Message requestMsg, EndpointAttributes endpoint
}
var requestType = GetRequestType(requestMsg, requestXml);
- try
+ try
{
var request = DataContractDeserializer.Instance.Parse(requestXml, requestType);
- IHttpRequest httpReq = null;
- IHttpResponse httpRes = null;
-
- httpReq = HttpContext.Current != null ? new HttpRequestWrapper(requestType.Name, HttpContext.Current.Request) : null;
- httpRes = HttpContext.Current != null
- ? new HttpResponseWrapper(HttpContext.Current.Response)
- : null;
+ var httpReq = HttpContext.Current != null
+ ? new HttpRequestWrapper(requestType.Name, HttpContext.Current.Request)
+ : null;
+ var httpRes = HttpContext.Current != null
+ ? new HttpResponseWrapper(HttpContext.Current.Response)
+ : null;
+
+ if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes))
+ return EmptyResponse(requestMsg, requestType);
+
var hasRequestFilters = EndpointHost.RequestFilters.Count > 0
|| FilterAttributeCache.GetRequestFilterAttributes(request.GetType()).Any();
@@ -81,13 +84,6 @@ protected Message ExecuteMessage(Message requestMsg, EndpointAttributes endpoint
var hasResponseFilters = EndpointHost.ResponseFilters.Count > 0
|| FilterAttributeCache.GetResponseFilterAttributes(response.GetType()).Any();
-
- if (hasResponseFilters && httpRes == null)
- {
- httpRes = HttpContext.Current != null
- ? new HttpResponseWrapper(HttpContext.Current.Response)
- : null;
- }
if (hasResponseFilters && EndpointHost.ApplyResponseFilters(httpReq, httpRes, response))
return EmptyResponse(requestMsg, requestType);
@@ -78,7 +78,7 @@ public T TryResolve<T>()
public IContentTypeFilter ContentTypeFilters { get; set; }
- public List<Action<IHttpRequest, IHttpResponse>> RawRequestFilters { get; set; }
+ public List<Action<IHttpRequest, IHttpResponse>> PreRequestFilters { get; set; }
public List<Action<IHttpRequest, IHttpResponse, object>> RequestFilters { get; set; }

0 comments on commit c152b96

Please sign in to comment.