HttpRequestOptions.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 host.
  52. /// </summary>
  53. /// <value>The host.</value>
  54. public string Host { get; set; }
  55. /// <summary>
  56. /// Gets or sets the progress.
  57. /// </summary>
  58. /// <value>The progress.</value>
  59. public IProgress<double> Progress { get; set; }
  60. /// <summary>
  61. /// Gets or sets a value indicating whether [enable HTTP compression].
  62. /// </summary>
  63. /// <value><c>true</c> if [enable HTTP compression]; otherwise, <c>false</c>.</value>
  64. public bool EnableHttpCompression { get; set; }
  65. public Dictionary<string, string> RequestHeaders { get; private set; }
  66. public string RequestContentType { get; set; }
  67. public string RequestContent { get; set; }
  68. public byte[] RequestContentBytes { get; set; }
  69. public bool BufferContent { get; set; }
  70. public bool LogRequest { get; set; }
  71. public bool LogErrorResponseBody { get; set; }
  72. private string GetHeaderValue(string name)
  73. {
  74. string value;
  75. RequestHeaders.TryGetValue(name, out value);
  76. return value;
  77. }
  78. /// <summary>
  79. /// Initializes a new instance of the <see cref="HttpRequestOptions"/> class.
  80. /// </summary>
  81. public HttpRequestOptions()
  82. {
  83. EnableHttpCompression = true;
  84. BufferContent = true;
  85. RequestHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  86. LogRequest = true;
  87. }
  88. }
  89. }