HttpRequestOptions.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. private string GetHeaderValue(string name)
  64. {
  65. string value;
  66. RequestHeaders.TryGetValue(name, out value);
  67. return value;
  68. }
  69. /// <summary>
  70. /// Initializes a new instance of the <see cref="HttpRequestOptions"/> class.
  71. /// </summary>
  72. public HttpRequestOptions()
  73. {
  74. EnableHttpCompression = true;
  75. RequestHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  76. }
  77. }
  78. }