IHttpResultFactory.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using ServiceStack.Web;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Threading.Tasks;
  6. namespace MediaBrowser.Controller.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>(IRequest 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>(IRequest 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>(IRequest 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. Task<object> GetStaticResult(IRequest requestContext,
  78. Guid cacheKey,
  79. DateTime? lastDateModified,
  80. TimeSpan? cacheDuration,
  81. string contentType, Func<Task<Stream>> factoryFn,
  82. IDictionary<string, string> responseHeaders = null,
  83. bool isHeadRequest = false);
  84. /// <summary>
  85. /// Gets the static result.
  86. /// </summary>
  87. /// <param name="requestContext">The request context.</param>
  88. /// <param name="options">The options.</param>
  89. /// <returns>System.Object.</returns>
  90. Task<object> GetStaticResult(IRequest requestContext, StaticResultOptions options);
  91. /// <summary>
  92. /// Gets the static file result.
  93. /// </summary>
  94. /// <param name="requestContext">The request context.</param>
  95. /// <param name="path">The path.</param>
  96. /// <param name="fileShare">The file share.</param>
  97. /// <returns>System.Object.</returns>
  98. Task<object> GetStaticFileResult(IRequest requestContext, string path, FileShare fileShare = FileShare.Read);
  99. /// <summary>
  100. /// Gets the static file result.
  101. /// </summary>
  102. /// <param name="requestContext">The request context.</param>
  103. /// <param name="options">The options.</param>
  104. /// <returns>System.Object.</returns>
  105. Task<object> GetStaticFileResult(IRequest requestContext,
  106. StaticFileResultOptions options);
  107. }
  108. }