IHttpClient.cs 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. /// Performs a GET request and returns the resulting stream
  15. /// </summary>
  16. /// <param name="url">The URL.</param>
  17. /// <param name="resourcePool">The resource pool.</param>
  18. /// <param name="cancellationToken">The cancellation token.</param>
  19. /// <returns>Task{Stream}.</returns>
  20. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  21. Task<Stream> Get(string url, SemaphoreSlim resourcePool, CancellationToken cancellationToken);
  22. /// <summary>
  23. /// Gets the specified URL.
  24. /// </summary>
  25. /// <param name="url">The URL.</param>
  26. /// <param name="cancellationToken">The cancellation token.</param>
  27. /// <returns>Task{Stream}.</returns>
  28. Task<Stream> Get(string url, CancellationToken cancellationToken);
  29. /// <summary>
  30. /// Performs a POST request
  31. /// </summary>
  32. /// <param name="url">The URL.</param>
  33. /// <param name="postData">Params to add to the POST data.</param>
  34. /// <param name="resourcePool">The resource pool.</param>
  35. /// <param name="cancellationToken">The cancellation token.</param>
  36. /// <returns>stream on success, null on failure</returns>
  37. /// <exception cref="System.ArgumentNullException">postData</exception>
  38. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  39. Task<Stream> Post(string url, Dictionary<string, string> postData, SemaphoreSlim resourcePool, CancellationToken cancellationToken);
  40. /// <summary>
  41. /// Posts the specified URL.
  42. /// </summary>
  43. /// <param name="url">The URL.</param>
  44. /// <param name="postData">The post data.</param>
  45. /// <param name="cancellationToken">The cancellation token.</param>
  46. /// <returns>Task{Stream}.</returns>
  47. Task<Stream> Post(string url, Dictionary<string, string> postData, CancellationToken cancellationToken);
  48. /// <summary>
  49. /// Downloads the contents of a given url into a temporary location
  50. /// </summary>
  51. /// <param name="url">The URL.</param>
  52. /// <param name="resourcePool">The resource pool.</param>
  53. /// <param name="cancellationToken">The cancellation token.</param>
  54. /// <param name="progress">The progress.</param>
  55. /// <param name="userAgent">The user agent.</param>
  56. /// <returns>Task{System.String}.</returns>
  57. /// <exception cref="System.ArgumentNullException">progress</exception>
  58. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  59. Task<string> GetTempFile(string url, SemaphoreSlim resourcePool, CancellationToken cancellationToken, IProgress<double> progress, string userAgent = null);
  60. /// <summary>
  61. /// Gets the temp file.
  62. /// </summary>
  63. /// <param name="url">The URL.</param>
  64. /// <param name="cancellationToken">The cancellation token.</param>
  65. /// <param name="progress">The progress.</param>
  66. /// <param name="userAgent">The user agent.</param>
  67. /// <returns>Task{System.String}.</returns>
  68. Task<string> GetTempFile(string url, CancellationToken cancellationToken, IProgress<double> progress, string userAgent = null);
  69. /// <summary>
  70. /// Downloads the contents of a given url into a MemoryStream
  71. /// </summary>
  72. /// <param name="url">The URL.</param>
  73. /// <param name="resourcePool">The resource pool.</param>
  74. /// <param name="cancellationToken">The cancellation token.</param>
  75. /// <returns>Task{MemoryStream}.</returns>
  76. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  77. Task<MemoryStream> GetMemoryStream(string url, SemaphoreSlim resourcePool, CancellationToken cancellationToken);
  78. /// <summary>
  79. /// Gets the memory stream.
  80. /// </summary>
  81. /// <param name="url">The URL.</param>
  82. /// <param name="cancellationToken">The cancellation token.</param>
  83. /// <returns>Task{MemoryStream}.</returns>
  84. Task<MemoryStream> GetMemoryStream(string url, CancellationToken cancellationToken);
  85. }
  86. }