IHttpResultFactory.cs 5.1 KB

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