From e2dcddc5ac43846baea0f9b1a0fc62844dd9ee1d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 23 Mar 2013 22:45:00 -0400 Subject: made compression and caching available to plugin api endpoints --- MediaBrowser.Common/Net/IHasResultFactory.cs | 17 +++++ MediaBrowser.Common/Net/IHttpResultFactory.cs | 92 ++++++++++++++++++++++++++- MediaBrowser.Common/Net/IRestfulService.cs | 9 +-- MediaBrowser.Common/Net/RouteInfo.cs | 28 -------- 4 files changed, 109 insertions(+), 37 deletions(-) create mode 100644 MediaBrowser.Common/Net/IHasResultFactory.cs delete mode 100644 MediaBrowser.Common/Net/RouteInfo.cs (limited to 'MediaBrowser.Common/Net') diff --git a/MediaBrowser.Common/Net/IHasResultFactory.cs b/MediaBrowser.Common/Net/IHasResultFactory.cs new file mode 100644 index 0000000000..d9da0c7e4e --- /dev/null +++ b/MediaBrowser.Common/Net/IHasResultFactory.cs @@ -0,0 +1,17 @@ +using ServiceStack.ServiceHost; + +namespace MediaBrowser.Common.Net +{ + /// + /// Interface IHasResultFactory + /// Services that require a ResultFactory should implement this + /// + public interface IHasResultFactory : IRequiresRequestContext + { + /// + /// Gets or sets the result factory. + /// + /// The result factory. + IHttpResultFactory ResultFactory { get; set; } + } +} diff --git a/MediaBrowser.Common/Net/IHttpResultFactory.cs b/MediaBrowser.Common/Net/IHttpResultFactory.cs index 565a2dce9c..55c0e5b9b3 100644 --- a/MediaBrowser.Common/Net/IHttpResultFactory.cs +++ b/MediaBrowser.Common/Net/IHttpResultFactory.cs @@ -1,9 +1,97 @@ -using System.IO; +using ServiceStack.ServiceHost; +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; namespace MediaBrowser.Common.Net { + /// + /// Interface IHttpResultFactory + /// public interface IHttpResultFactory { - object GetResult(Stream stream, string contentType); + /// + /// Throws the error. + /// + /// The status code. + /// The error message. + /// The response headers. + void ThrowError(int statusCode, string errorMessage, IDictionary responseHeaders = null); + + /// + /// Gets the result. + /// + /// The content. + /// Type of the content. + /// The response headers. + /// System.Object. + object GetResult(object content, string contentType, IDictionary responseHeaders = null); + + /// + /// Gets the optimized result. + /// + /// + /// The request context. + /// The result. + /// The response headers. + /// System.Object. + object GetOptimizedResult(IRequestContext requestContext, T result, IDictionary responseHeaders = null) + where T : class; + + /// + /// Gets the optimized result using cache. + /// + /// + /// The request context. + /// The cache key. + /// The last date modified. + /// Duration of the cache. + /// The factory function that creates the response object. + /// The response headers. + /// System.Object. + object GetOptimizedResultUsingCache(IRequestContext requestContext, Guid cacheKey, DateTime lastDateModified, TimeSpan? cacheDuration, Func factoryFn, IDictionary responseHeaders = null) + where T : class; + + /// + /// Gets the cached result. + /// + /// + /// The request context. + /// The cache key. + /// The last date modified. + /// Duration of the cache. + /// The factory fn. + /// Type of the content. + /// The response headers. + /// System.Object. + object GetCachedResult(IRequestContext requestContext, Guid cacheKey, DateTime lastDateModified, TimeSpan? cacheDuration, Func factoryFn, string contentType, IDictionary responseHeaders = null) + where T : class; + + /// + /// Gets the static result. + /// + /// The request context. + /// The cache key. + /// The last date modified. + /// Duration of the cache. + /// Type of the content. + /// The factory fn. + /// The response headers. + /// if set to true [is head request]. + /// System.Object. + object GetStaticResult(IRequestContext requestContext, Guid cacheKey, DateTime? lastDateModified, + TimeSpan? cacheDuration, string contentType, Func> factoryFn, + IDictionary responseHeaders = null, bool isHeadRequest = false); + + /// + /// Gets the static file result. + /// + /// The request context. + /// The path. + /// The response headers. + /// if set to true [is head request]. + /// System.Object. + object GetStaticFileResult(IRequestContext requestContext, string path, IDictionary responseHeaders = null, bool isHeadRequest = false); } } diff --git a/MediaBrowser.Common/Net/IRestfulService.cs b/MediaBrowser.Common/Net/IRestfulService.cs index 9f37676450..7a1b267951 100644 --- a/MediaBrowser.Common/Net/IRestfulService.cs +++ b/MediaBrowser.Common/Net/IRestfulService.cs @@ -1,16 +1,11 @@ -using System.Collections.Generic; +using ServiceStack.ServiceHost; namespace MediaBrowser.Common.Net { /// /// Interface IRestfulService /// - public interface IRestfulService + public interface IRestfulService : IService { - /// - /// Gets the routes. - /// - /// IEnumerable{RouteInfo}. - IEnumerable GetRoutes(); } } diff --git a/MediaBrowser.Common/Net/RouteInfo.cs b/MediaBrowser.Common/Net/RouteInfo.cs deleted file mode 100644 index 379aff9c5e..0000000000 --- a/MediaBrowser.Common/Net/RouteInfo.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; - -namespace MediaBrowser.Common.Net -{ - /// - /// Class RouteInfo - /// - public class RouteInfo - { - /// - /// Gets or sets the path. - /// - /// The path. - public string Path { get; set; } - - /// - /// Gets or sets the verbs. - /// - /// The verbs. - public string Verbs { get; set; } - - /// - /// Gets or sets the type of the request. - /// - /// The type of the request. - public Type RequestType { get; set; } - } -} -- cgit v1.2.3