2
0

IHttpResultFactory.cs 4.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using ServiceStack.ServiceHost;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Threading.Tasks;
  6. namespace MediaBrowser.Common.Net
  7. {
  8. /// <summary>
  9. /// Interface IHttpResultFactory
  10. /// </summary>
  11. public interface IHttpResultFactory
  12. {
  13. /// <summary>
  14. /// Throws the error.
  15. /// </summary>
  16. /// <param name="statusCode">The status code.</param>
  17. /// <param name="errorMessage">The error message.</param>
  18. /// <param name="responseHeaders">The response headers.</param>
  19. void ThrowError(int statusCode, string errorMessage, IDictionary<string, string> responseHeaders = null);
  20. /// <summary>
  21. /// Gets the result.
  22. /// </summary>
  23. /// <param name="content">The content.</param>
  24. /// <param name="contentType">Type of the content.</param>
  25. /// <param name="responseHeaders">The response headers.</param>
  26. /// <returns>System.Object.</returns>
  27. object GetResult(object content, string contentType, IDictionary<string,string> responseHeaders = null);
  28. /// <summary>
  29. /// Gets the optimized result.
  30. /// </summary>
  31. /// <typeparam name="T"></typeparam>
  32. /// <param name="requestContext">The request context.</param>
  33. /// <param name="result">The result.</param>
  34. /// <param name="responseHeaders">The response headers.</param>
  35. /// <returns>System.Object.</returns>
  36. object GetOptimizedResult<T>(IRequestContext requestContext, T result, IDictionary<string, string> responseHeaders = null)
  37. where T : class;
  38. /// <summary>
  39. /// Gets the optimized result using cache.
  40. /// </summary>
  41. /// <typeparam name="T"></typeparam>
  42. /// <param name="requestContext">The request context.</param>
  43. /// <param name="cacheKey">The cache key.</param>
  44. /// <param name="lastDateModified">The last date modified.</param>
  45. /// <param name="cacheDuration">Duration of the cache.</param>
  46. /// <param name="factoryFn">The factory function that creates the response object.</param>
  47. /// <param name="responseHeaders">The response headers.</param>
  48. /// <returns>System.Object.</returns>
  49. object GetOptimizedResultUsingCache<T>(IRequestContext requestContext, Guid cacheKey, DateTime lastDateModified, TimeSpan? cacheDuration, Func<T> factoryFn, IDictionary<string, string> responseHeaders = null)
  50. where T : class;
  51. /// <summary>
  52. /// Gets the cached result.
  53. /// </summary>
  54. /// <typeparam name="T"></typeparam>
  55. /// <param name="requestContext">The request context.</param>
  56. /// <param name="cacheKey">The cache key.</param>
  57. /// <param name="lastDateModified">The last date modified.</param>
  58. /// <param name="cacheDuration">Duration of the cache.</param>
  59. /// <param name="factoryFn">The factory fn.</param>
  60. /// <param name="contentType">Type of the content.</param>
  61. /// <param name="responseHeaders">The response headers.</param>
  62. /// <returns>System.Object.</returns>
  63. object GetCachedResult<T>(IRequestContext requestContext, Guid cacheKey, DateTime lastDateModified, TimeSpan? cacheDuration, Func<T> factoryFn, string contentType, IDictionary<string, string> responseHeaders = null)
  64. where T : class;
  65. /// <summary>
  66. /// Gets the static result.
  67. /// </summary>
  68. /// <param name="requestContext">The request context.</param>
  69. /// <param name="cacheKey">The cache key.</param>
  70. /// <param name="lastDateModified">The last date modified.</param>
  71. /// <param name="cacheDuration">Duration of the cache.</param>
  72. /// <param name="contentType">Type of the content.</param>
  73. /// <param name="factoryFn">The factory fn.</param>
  74. /// <param name="responseHeaders">The response headers.</param>
  75. /// <param name="isHeadRequest">if set to <c>true</c> [is head request].</param>
  76. /// <returns>System.Object.</returns>
  77. object GetStaticResult(IRequestContext requestContext, Guid cacheKey, DateTime? lastDateModified,
  78. TimeSpan? cacheDuration, string contentType, Func<Task<Stream>> factoryFn,
  79. IDictionary<string, string> responseHeaders = null, bool isHeadRequest = false);
  80. /// <summary>
  81. /// Gets the static file result.
  82. /// </summary>
  83. /// <param name="requestContext">The request context.</param>
  84. /// <param name="path">The path.</param>
  85. /// <param name="responseHeaders">The response headers.</param>
  86. /// <param name="isHeadRequest">if set to <c>true</c> [is head request].</param>
  87. /// <returns>System.Object.</returns>
  88. object GetStaticFileResult(IRequestContext requestContext, string path, IDictionary<string, string> responseHeaders = null, bool isHeadRequest = false);
  89. }
  90. }