HttpHeaderUtility.cs 968 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Rac.Models;
  5. namespace Rac.Tools
  6. {
  7. internal static class HttpHeaderUtility
  8. {
  9. public static HttpHeader Parse(string line)
  10. {
  11. var a = line.Split(':');
  12. var k = a[0];
  13. var v = k.Length == line.Length
  14. ? ""
  15. : line.Substring(k.Length + 1).Trim();
  16. return new HttpHeader { Name = k, Value = v };
  17. }
  18. public static HttpHeader[] Parse(string[] lines)
  19. {
  20. return lines.Select(Parse).ToArray();
  21. }
  22. public static HttpHeader[] ParseStringLines(string lines)
  23. {
  24. return Parse(lines.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries));
  25. }
  26. public static string ToStringLines(this IEnumerable<HttpHeader> items)
  27. {
  28. return string.Join("\r\n", items.Select(p => p.ToString()));
  29. }
  30. }
  31. }