HeaderParser.cs 972 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Collections.Generic;
  2. namespace BestHTTP.Extensions
  3. {
  4. /// <summary>
  5. /// Will parse a comma-separeted header value
  6. /// </summary>
  7. public sealed class HeaderParser : KeyValuePairList
  8. {
  9. public HeaderParser(string headerStr)
  10. {
  11. base.Values = Parse(headerStr);
  12. }
  13. private List<HeaderValue> Parse(string headerStr)
  14. {
  15. List<HeaderValue> result = new List<HeaderValue>();
  16. int pos = 0;
  17. try
  18. {
  19. while (pos < headerStr.Length)
  20. {
  21. HeaderValue current = new HeaderValue();
  22. current.Parse(headerStr, ref pos);
  23. result.Add(current);
  24. }
  25. }
  26. catch(System.Exception ex)
  27. {
  28. HTTPManager.Logger.Exception("HeaderParser - Parse", headerStr, ex);
  29. }
  30. return result;
  31. }
  32. }
  33. }