HttpRequestOptions.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. namespace MediaBrowser.Common.Net
  5. {
  6. /// <summary>
  7. /// Class HttpRequestOptions
  8. /// </summary>
  9. public class HttpRequestOptions
  10. {
  11. /// <summary>
  12. /// Gets or sets the URL.
  13. /// </summary>
  14. /// <value>The URL.</value>
  15. public string Url { get; set; }
  16. /// <summary>
  17. /// Gets or sets the accept header.
  18. /// </summary>
  19. /// <value>The accept header.</value>
  20. public string AcceptHeader
  21. {
  22. get { return GetHeaderValue("Accept"); }
  23. set
  24. {
  25. RequestHeaders["Accept"] = value;
  26. }
  27. }
  28. /// <summary>
  29. /// Gets or sets the cancellation token.
  30. /// </summary>
  31. /// <value>The cancellation token.</value>
  32. public CancellationToken CancellationToken { get; set; }
  33. /// <summary>
  34. /// Gets or sets the resource pool.
  35. /// </summary>
  36. /// <value>The resource pool.</value>
  37. public SemaphoreSlim ResourcePool { get; set; }
  38. /// <summary>
  39. /// Gets or sets the user agent.
  40. /// </summary>
  41. /// <value>The user agent.</value>
  42. public string UserAgent
  43. {
  44. get { return GetHeaderValue("User-Agent"); }
  45. set
  46. {
  47. RequestHeaders["User-Agent"] = value;
  48. }
  49. }
  50. /// <summary>
  51. /// Gets or sets the progress.
  52. /// </summary>
  53. /// <value>The progress.</value>
  54. public IProgress<double> Progress { get; set; }
  55. /// <summary>
  56. /// Gets or sets a value indicating whether [enable HTTP compression].
  57. /// </summary>
  58. /// <value><c>true</c> if [enable HTTP compression]; otherwise, <c>false</c>.</value>
  59. public bool EnableHttpCompression { get; set; }
  60. public Dictionary<string, string> RequestHeaders { get; private set; }
  61. public string RequestContentType { get; set; }
  62. public string RequestContent { get; set; }
  63. public bool BufferContent { get; set; }
  64. public HttpRequestCachePolicy CachePolicy { get; set; }
  65. private string GetHeaderValue(string name)
  66. {
  67. string value;
  68. RequestHeaders.TryGetValue(name, out value);
  69. return value;
  70. }
  71. /// <summary>
  72. /// Initializes a new instance of the <see cref="HttpRequestOptions"/> class.
  73. /// </summary>
  74. public HttpRequestOptions()
  75. {
  76. EnableHttpCompression = true;
  77. BufferContent = true;
  78. CachePolicy = HttpRequestCachePolicy.None;
  79. RequestHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  80. }
  81. }
  82. public enum HttpRequestCachePolicy
  83. {
  84. None = 1,
  85. Validate = 2
  86. }
  87. }