12345678910111213141516171819202122232425262728293031323334353637 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Rac.Models;
- namespace Rac.Tools
- {
- internal static class HttpHeaderUtility
- {
- public static HttpHeader Parse(string line)
- {
- var a = line.Split(':');
- var k = a[0];
- var v = k.Length == line.Length
- ? ""
- : line.Substring(k.Length + 1).Trim();
- return new HttpHeader { Name = k, Value = v };
- }
- public static HttpHeader[] Parse(string[] lines)
- {
- return lines.Select(Parse).ToArray();
- }
- public static HttpHeader[] ParseStringLines(string lines)
- {
- return Parse(lines.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries));
- }
- public static string ToStringLines(this IEnumerable<HttpHeader> items)
- {
- return string.Join("\r\n", items.Select(p => p.ToString()));
- }
- }
- }
|