IHttpClient.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. public interface IHttpClient : IDisposable
  9. {
  10. /// <summary>
  11. /// Performs a GET request and returns the resulting stream
  12. /// </summary>
  13. /// <param name="url">The URL.</param>
  14. /// <param name="resourcePool">The resource pool.</param>
  15. /// <param name="cancellationToken">The cancellation token.</param>
  16. /// <returns>Task{Stream}.</returns>
  17. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  18. Task<Stream> Get(string url, SemaphoreSlim resourcePool, CancellationToken cancellationToken);
  19. /// <summary>
  20. /// Performs a POST request
  21. /// </summary>
  22. /// <param name="url">The URL.</param>
  23. /// <param name="postData">Params to add to the POST data.</param>
  24. /// <param name="resourcePool">The resource pool.</param>
  25. /// <param name="cancellationToken">The cancellation token.</param>
  26. /// <returns>stream on success, null on failure</returns>
  27. /// <exception cref="System.ArgumentNullException">postData</exception>
  28. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  29. Task<Stream> Post(string url, Dictionary<string, string> postData, SemaphoreSlim resourcePool, CancellationToken cancellationToken);
  30. /// <summary>
  31. /// Downloads the contents of a given url into a temporary location
  32. /// </summary>
  33. /// <param name="url">The URL.</param>
  34. /// <param name="resourcePool">The resource pool.</param>
  35. /// <param name="cancellationToken">The cancellation token.</param>
  36. /// <param name="progress">The progress.</param>
  37. /// <param name="userAgent">The user agent.</param>
  38. /// <returns>Task{System.String}.</returns>
  39. /// <exception cref="System.ArgumentNullException">progress</exception>
  40. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  41. Task<string> GetTempFile(string url, SemaphoreSlim resourcePool, CancellationToken cancellationToken, IProgress<double> progress, string userAgent = null);
  42. /// <summary>
  43. /// Downloads the contents of a given url into a MemoryStream
  44. /// </summary>
  45. /// <param name="url">The URL.</param>
  46. /// <param name="resourcePool">The resource pool.</param>
  47. /// <param name="cancellationToken">The cancellation token.</param>
  48. /// <returns>Task{MemoryStream}.</returns>
  49. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  50. Task<MemoryStream> GetMemoryStream(string url, SemaphoreSlim resourcePool, CancellationToken cancellationToken);
  51. /// <summary>
  52. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  53. /// </summary>
  54. void Dispose();
  55. }
  56. }