made compression and caching available to plugin api endpoints

This commit is contained in:
Luke Pulverenti
2013-03-23 22:45:00 -04:00
parent 521ec49361
commit e2dcddc5ac
40 changed files with 1094 additions and 756 deletions

View File

@@ -38,6 +38,15 @@
</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="ServiceStack.Common">
<HintPath>..\packages\ServiceStack.Common.3.9.42\lib\net35\ServiceStack.Common.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Interfaces">
<HintPath>..\packages\ServiceStack.Common.3.9.42\lib\net35\ServiceStack.Interfaces.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Text">
<HintPath>..\packages\ServiceStack.Text.3.9.42\lib\net35\ServiceStack.Text.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
@@ -62,6 +71,7 @@
<Compile Include="Net\BasePeriodicWebSocketListener.cs" />
<Compile Include="Configuration\IApplicationPaths.cs" />
<Compile Include="Net\HttpRequestOptions.cs" />
<Compile Include="Net\IHasResultFactory.cs" />
<Compile Include="Net\IHttpResultFactory.cs" />
<Compile Include="Net\IServerManager.cs" />
<Compile Include="Net\IWebSocketListener.cs" />
@@ -75,7 +85,6 @@
<Compile Include="Net\IWebSocketConnection.cs" />
<Compile Include="Net\IWebSocketServer.cs" />
<Compile Include="Net\MimeTypes.cs" />
<Compile Include="Net\RouteInfo.cs" />
<Compile Include="Net\UdpMessageReceivedEventArgs.cs" />
<Compile Include="Net\WebSocketConnectEventArgs.cs" />
<Compile Include="Net\WebSocketMessageType.cs" />
@@ -107,6 +116,7 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj">

View File

@@ -0,0 +1,17 @@
using ServiceStack.ServiceHost;
namespace MediaBrowser.Common.Net
{
/// <summary>
/// Interface IHasResultFactory
/// Services that require a ResultFactory should implement this
/// </summary>
public interface IHasResultFactory : IRequiresRequestContext
{
/// <summary>
/// Gets or sets the result factory.
/// </summary>
/// <value>The result factory.</value>
IHttpResultFactory ResultFactory { get; set; }
}
}

View File

@@ -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
{
/// <summary>
/// Interface IHttpResultFactory
/// </summary>
public interface IHttpResultFactory
{
object GetResult(Stream stream, string contentType);
/// <summary>
/// Throws the error.
/// </summary>
/// <param name="statusCode">The status code.</param>
/// <param name="errorMessage">The error message.</param>
/// <param name="responseHeaders">The response headers.</param>
void ThrowError(int statusCode, string errorMessage, IDictionary<string, string> responseHeaders = null);
/// <summary>
/// Gets the result.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="contentType">Type of the content.</param>
/// <param name="responseHeaders">The response headers.</param>
/// <returns>System.Object.</returns>
object GetResult(object content, string contentType, IDictionary<string,string> responseHeaders = null);
/// <summary>
/// Gets the optimized result.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="requestContext">The request context.</param>
/// <param name="result">The result.</param>
/// <param name="responseHeaders">The response headers.</param>
/// <returns>System.Object.</returns>
object GetOptimizedResult<T>(IRequestContext requestContext, T result, IDictionary<string, string> responseHeaders = null)
where T : class;
/// <summary>
/// Gets the optimized result using cache.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="requestContext">The request context.</param>
/// <param name="cacheKey">The cache key.</param>
/// <param name="lastDateModified">The last date modified.</param>
/// <param name="cacheDuration">Duration of the cache.</param>
/// <param name="factoryFn">The factory function that creates the response object.</param>
/// <param name="responseHeaders">The response headers.</param>
/// <returns>System.Object.</returns>
object GetOptimizedResultUsingCache<T>(IRequestContext requestContext, Guid cacheKey, DateTime lastDateModified, TimeSpan? cacheDuration, Func<T> factoryFn, IDictionary<string, string> responseHeaders = null)
where T : class;
/// <summary>
/// Gets the cached result.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="requestContext">The request context.</param>
/// <param name="cacheKey">The cache key.</param>
/// <param name="lastDateModified">The last date modified.</param>
/// <param name="cacheDuration">Duration of the cache.</param>
/// <param name="factoryFn">The factory fn.</param>
/// <param name="contentType">Type of the content.</param>
/// <param name="responseHeaders">The response headers.</param>
/// <returns>System.Object.</returns>
object GetCachedResult<T>(IRequestContext requestContext, Guid cacheKey, DateTime lastDateModified, TimeSpan? cacheDuration, Func<T> factoryFn, string contentType, IDictionary<string, string> responseHeaders = null)
where T : class;
/// <summary>
/// Gets the static result.
/// </summary>
/// <param name="requestContext">The request context.</param>
/// <param name="cacheKey">The cache key.</param>
/// <param name="lastDateModified">The last date modified.</param>
/// <param name="cacheDuration">Duration of the cache.</param>
/// <param name="contentType">Type of the content.</param>
/// <param name="factoryFn">The factory fn.</param>
/// <param name="responseHeaders">The response headers.</param>
/// <param name="isHeadRequest">if set to <c>true</c> [is head request].</param>
/// <returns>System.Object.</returns>
object GetStaticResult(IRequestContext requestContext, Guid cacheKey, DateTime? lastDateModified,
TimeSpan? cacheDuration, string contentType, Func<Task<Stream>> factoryFn,
IDictionary<string, string> responseHeaders = null, bool isHeadRequest = false);
/// <summary>
/// Gets the static file result.
/// </summary>
/// <param name="requestContext">The request context.</param>
/// <param name="path">The path.</param>
/// <param name="responseHeaders">The response headers.</param>
/// <param name="isHeadRequest">if set to <c>true</c> [is head request].</param>
/// <returns>System.Object.</returns>
object GetStaticFileResult(IRequestContext requestContext, string path, IDictionary<string, string> responseHeaders = null, bool isHeadRequest = false);
}
}

View File

@@ -1,16 +1,11 @@
using System.Collections.Generic;
using ServiceStack.ServiceHost;
namespace MediaBrowser.Common.Net
{
/// <summary>
/// Interface IRestfulService
/// </summary>
public interface IRestfulService
public interface IRestfulService : IService
{
/// <summary>
/// Gets the routes.
/// </summary>
/// <returns>IEnumerable{RouteInfo}.</returns>
IEnumerable<RouteInfo> GetRoutes();
}
}

View File

@@ -1,28 +0,0 @@
using System;
namespace MediaBrowser.Common.Net
{
/// <summary>
/// Class RouteInfo
/// </summary>
public class RouteInfo
{
/// <summary>
/// Gets or sets the path.
/// </summary>
/// <value>The path.</value>
public string Path { get; set; }
/// <summary>
/// Gets or sets the verbs.
/// </summary>
/// <value>The verbs.</value>
public string Verbs { get; set; }
/// <summary>
/// Gets or sets the type of the request.
/// </summary>
/// <value>The type of the request.</value>
public Type RequestType { get; set; }
}
}

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ServiceStack.Common" version="3.9.42" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.42" targetFramework="net45" />
</packages>