2
0

HttpRequestOptions.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 bool LogRequest { get; set; }
  65. public bool LogErrorResponseBody { get; set; }
  66. public HttpRequestCachePolicy CachePolicy { get; set; }
  67. private string GetHeaderValue(string name)
  68. {
  69. string value;
  70. RequestHeaders.TryGetValue(name, out value);
  71. return value;
  72. }
  73. /// <summary>
  74. /// Initializes a new instance of the <see cref="HttpRequestOptions"/> class.
  75. /// </summary>
  76. public HttpRequestOptions()
  77. {
  78. EnableHttpCompression = true;
  79. BufferContent = true;
  80. CachePolicy = HttpRequestCachePolicy.None;
  81. RequestHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  82. LogRequest = true;
  83. }
  84. }
  85. public enum HttpRequestCachePolicy
  86. {
  87. None = 1,
  88. Validate = 2
  89. }
  90. }