You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.4 KiB

9 months ago
9 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Apewer.Network
  5. {
  6. /// <summary>HTTP 头。</summary>
  7. [Serializable]
  8. public sealed class HttpHeader
  9. {
  10. string _name = null;
  11. string _value = null;
  12. /// <summary>名称。</summary>
  13. public string Name { get => _name; set => _name = value?.Trim(); }
  14. /// <summary>值。</summary>
  15. public string Value { get => _value; set => _value = value?.Trim(); }
  16. /// <summary>创建 HTTP 头的实例。</summary>
  17. public HttpHeader() { }
  18. /// <summary>创建 HTTP 头的实例。</summary>
  19. /// <exception cref="ArgumentException" />
  20. public HttpHeader(KeyValuePair<string, string> keyValuePair)
  21. {
  22. if (keyValuePair.Key.IsEmpty()) throw new ArgumentNullException("Key 无效。");
  23. Name = keyValuePair.Key;
  24. Value = keyValuePair.Value;
  25. }
  26. /// <summary>创建 HTTP 头的实例。</summary>
  27. /// <exception cref="ArgumentNullException" />
  28. public HttpHeader(string name, string value)
  29. {
  30. if (name.IsEmpty()) throw new ArgumentNullException(nameof(name));
  31. Name = name;
  32. Value = value;
  33. }
  34. /// <summary></summary>
  35. public override string ToString() => $"{Name}: {Value}";
  36. }
  37. }