diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-11-11 14:55:12 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-11-11 14:55:12 -0500 |
| commit | 406e6cb8132c1b8ade2872d44d7183267dd51ca8 (patch) | |
| tree | f9088ce1219351cee1976ba9fa57ed6341eeed9a /ServiceStack/ServiceStackHost.Runtime.cs | |
| parent | f8b8de13b752c49360bbe10502cc067be89937ae (diff) | |
update portable projects
Diffstat (limited to 'ServiceStack/ServiceStackHost.Runtime.cs')
| -rw-r--r-- | ServiceStack/ServiceStackHost.Runtime.cs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/ServiceStack/ServiceStackHost.Runtime.cs b/ServiceStack/ServiceStackHost.Runtime.cs new file mode 100644 index 000000000..1a1656a0e --- /dev/null +++ b/ServiceStack/ServiceStackHost.Runtime.cs @@ -0,0 +1,74 @@ +// Copyright (c) Service Stack LLC. All Rights Reserved. +// License: https://raw.github.com/ServiceStack/ServiceStack/master/license.txt + + +using MediaBrowser.Model.Services; +using ServiceStack.Support.WebHost; + +namespace ServiceStack +{ + public abstract partial class ServiceStackHost + { + /// <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 virtual bool ApplyRequestFilters(IRequest req, IResponse res, object requestDto) + { + if (res.IsClosed) return res.IsClosed; + + //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]; + attribute.RequestFilter(req, res, requestDto); + if (res.IsClosed) return res.IsClosed; + } + + if (res.IsClosed) return res.IsClosed; + + //Exec global filters + foreach (var requestFilter in GlobalRequestFilters) + { + requestFilter(req, res, requestDto); + if (res.IsClosed) return res.IsClosed; + } + + //Exec remaining RequestFilter attributes with Priority >= 0 + for (; i < attributes.Length && attributes[i].Priority >= 0; i++) + { + var attribute = attributes[i]; + attribute.RequestFilter(req, res, requestDto); + if (res.IsClosed) return res.IsClosed; + } + + return res.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 virtual bool ApplyResponseFilters(IRequest req, IResponse res, object response) + { + if (response != null) + { + if (res.IsClosed) return res.IsClosed; + } + + //Exec global filters + foreach (var responseFilter in GlobalResponseFilters) + { + responseFilter(req, res, response); + if (res.IsClosed) return res.IsClosed; + } + + return res.IsClosed; + } + } + +}
\ No newline at end of file |
