IHttpClient.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. namespace MediaBrowser.Common.Net
  7. {
  8. /// <summary>
  9. /// Interface IHttpClient
  10. /// </summary>
  11. public interface IHttpClient : IDisposable
  12. {
  13. /// <summary>
  14. /// Gets the response.
  15. /// </summary>
  16. /// <param name="options">The options.</param>
  17. /// <returns>Task{HttpResponseInfo}.</returns>
  18. Task<HttpResponseInfo> GetResponse(HttpRequestOptions options);
  19. /// <summary>
  20. /// Performs a GET request and returns the resulting stream
  21. /// </summary>
  22. /// <param name="url">The URL.</param>
  23. /// <param name="resourcePool">The resource pool.</param>
  24. /// <param name="cancellationToken">The cancellation token.</param>
  25. /// <returns>Task{Stream}.</returns>
  26. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  27. Task<Stream> Get(string url, SemaphoreSlim resourcePool, CancellationToken cancellationToken);
  28. /// <summary>
  29. /// Gets the specified URL.
  30. /// </summary>
  31. /// <param name="url">The URL.</param>
  32. /// <param name="cancellationToken">The cancellation token.</param>
  33. /// <returns>Task{Stream}.</returns>
  34. Task<Stream> Get(string url, CancellationToken cancellationToken);
  35. /// <summary>
  36. /// Gets the specified options.
  37. /// </summary>
  38. /// <param name="options">The options.</param>
  39. /// <returns>Task{Stream}.</returns>
  40. Task<Stream> Get(HttpRequestOptions options);
  41. /// <summary>
  42. /// Sends the asynchronous.
  43. /// </summary>
  44. /// <param name="options">The options.</param>
  45. /// <param name="httpMethod">The HTTP method.</param>
  46. /// <returns>Task{HttpResponseInfo}.</returns>
  47. Task<HttpResponseInfo> SendAsync(HttpRequestOptions options, string httpMethod);
  48. /// <summary>
  49. /// Performs a POST request
  50. /// </summary>
  51. /// <param name="url">The URL.</param>
  52. /// <param name="postData">Params to add to the POST data.</param>
  53. /// <param name="resourcePool">The resource pool.</param>
  54. /// <param name="cancellationToken">The cancellation token.</param>
  55. /// <returns>stream on success, null on failure</returns>
  56. /// <exception cref="System.ArgumentNullException">postData</exception>
  57. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  58. Task<Stream> Post(string url, Dictionary<string, string> postData, SemaphoreSlim resourcePool, CancellationToken cancellationToken);
  59. /// <summary>
  60. /// Posts the specified URL.
  61. /// </summary>
  62. /// <param name="url">The URL.</param>
  63. /// <param name="postData">The post data.</param>
  64. /// <param name="cancellationToken">The cancellation token.</param>
  65. /// <returns>Task{Stream}.</returns>
  66. Task<Stream> Post(string url, Dictionary<string, string> postData, CancellationToken cancellationToken);
  67. /// <summary>
  68. /// Posts the specified options with post data
  69. /// </summary>
  70. /// <param name="options">The options</param>
  71. /// <param name="postData">The post data</param>
  72. /// <returns>Task{Stream}</returns>
  73. Task<Stream> Post(HttpRequestOptions options, Dictionary<string, string> postData);
  74. /// <summary>
  75. /// Posts the specified options.
  76. /// </summary>
  77. /// <param name="options">The options.</param>
  78. /// <returns>Task{HttpResponseInfo}.</returns>
  79. Task<HttpResponseInfo> Post(HttpRequestOptions options);
  80. /// <summary>
  81. /// Downloads the contents of a given url into a temporary location
  82. /// </summary>
  83. /// <param name="options">The options.</param>
  84. /// <returns>Task{System.String}.</returns>
  85. /// <exception cref="System.ArgumentNullException">progress</exception>
  86. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  87. Task<string> GetTempFile(HttpRequestOptions options);
  88. /// <summary>
  89. /// Gets the temporary file response.
  90. /// </summary>
  91. /// <param name="options">The options.</param>
  92. /// <returns>Task{HttpResponseInfo}.</returns>
  93. Task<HttpResponseInfo> GetTempFileResponse(HttpRequestOptions options);
  94. }
  95. }