IHttpResultFactory.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. object GetAsyncStreamWriter(IAsyncStreamSource streamSource);
  29. /// <summary>
  30. /// Gets the optimized result.
  31. /// </summary>
  32. /// <typeparam name="T"></typeparam>
  33. /// <param name="requestContext">The request context.</param>
  34. /// <param name="result">The result.</param>
  35. /// <param name="responseHeaders">The response headers.</param>
  36. /// <returns>System.Object.</returns>
  37. object GetOptimizedResult<T>(IRequest requestContext, T result, IDictionary<string, string> responseHeaders = null)
  38. where T : class;
  39. /// <summary>
  40. /// Gets the optimized result using cache.
  41. /// </summary>
  42. /// <typeparam name="T"></typeparam>
  43. /// <param name="requestContext">The request context.</param>
  44. /// <param name="cacheKey">The cache key.</param>
  45. /// <param name="lastDateModified">The last date modified.</param>
  46. /// <param name="cacheDuration">Duration of the cache.</param>
  47. /// <param name="factoryFn">The factory function that creates the response object.</param>
  48. /// <param name="responseHeaders">The response headers.</param>
  49. /// <returns>System.Object.</returns>
  50. object GetOptimizedResultUsingCache<T>(IRequest requestContext, Guid cacheKey, DateTime? lastDateModified, TimeSpan? cacheDuration, Func<T> factoryFn, IDictionary<string, string> responseHeaders = null)
  51. where T : class;
  52. /// <summary>
  53. /// Gets the cached result.
  54. /// </summary>
  55. /// <typeparam name="T"></typeparam>
  56. /// <param name="requestContext">The request context.</param>
  57. /// <param name="cacheKey">The cache key.</param>
  58. /// <param name="lastDateModified">The last date modified.</param>
  59. /// <param name="cacheDuration">Duration of the cache.</param>
  60. /// <param name="factoryFn">The factory fn.</param>
  61. /// <param name="contentType">Type of the content.</param>
  62. /// <param name="responseHeaders">The response headers.</param>
  63. /// <returns>System.Object.</returns>
  64. object GetCachedResult<T>(IRequest requestContext, Guid cacheKey, DateTime? lastDateModified, TimeSpan? cacheDuration, Func<T> factoryFn, string contentType, IDictionary<string, string> responseHeaders = null)
  65. where T : class;
  66. /// <summary>
  67. /// Gets the static result.
  68. /// </summary>
  69. /// <param name="requestContext">The request context.</param>
  70. /// <param name="cacheKey">The cache key.</param>
  71. /// <param name="lastDateModified">The last date modified.</param>
  72. /// <param name="cacheDuration">Duration of the cache.</param>
  73. /// <param name="contentType">Type of the content.</param>
  74. /// <param name="factoryFn">The factory fn.</param>
  75. /// <param name="responseHeaders">The response headers.</param>
  76. /// <param name="isHeadRequest">if set to <c>true</c> [is head request].</param>
  77. /// <returns>System.Object.</returns>
  78. Task<object> GetStaticResult(IRequest requestContext,
  79. Guid cacheKey,
  80. DateTime? lastDateModified,
  81. TimeSpan? cacheDuration,
  82. string contentType, Func<Task<Stream>> factoryFn,
  83. IDictionary<string, string> responseHeaders = null,
  84. bool isHeadRequest = false);
  85. /// <summary>
  86. /// Gets the static result.
  87. /// </summary>
  88. /// <param name="requestContext">The request context.</param>
  89. /// <param name="options">The options.</param>
  90. /// <returns>System.Object.</returns>
  91. Task<object> GetStaticResult(IRequest requestContext, StaticResultOptions options);
  92. /// <summary>
  93. /// Gets the static file result.
  94. /// </summary>
  95. /// <param name="requestContext">The request context.</param>
  96. /// <param name="path">The path.</param>
  97. /// <param name="fileShare">The file share.</param>
  98. /// <returns>System.Object.</returns>
  99. Task<object> GetStaticFileResult(IRequest requestContext, string path, FileShare fileShare = FileShare.Read);
  100. /// <summary>
  101. /// Gets the static file result.
  102. /// </summary>
  103. /// <param name="requestContext">The request context.</param>
  104. /// <param name="options">The options.</param>
  105. /// <returns>System.Object.</returns>
  106. Task<object> GetStaticFileResult(IRequest requestContext,
  107. StaticFileResultOptions options);
  108. }
  109. }