private void Parse() { var lines = RequestString.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); Headers = new List<Header>(); for (int i = 1; i < lines.Length; i++) { Regex headerRegex = new Regex(@"^([a-zA-Z\-]*):\s(.*)$"); Regex portRegex = new Regex(@"^\w+:([\d]{1,5})$"); var match = headerRegex.Match(lines[i].Trim()); Header header = new Header { Name = match.Groups[1].Value, Value = match.Groups[2].Value, }; if (header.Name == "Host") { Host = header.Value; match = portRegex.Match(Host); if (match.Success) { ushort temp; UInt16.TryParse(match.Groups[1].Value, out temp); Port = temp; } }else if(header.Name == "User-Agent"){ UserAgent = header.Value; } Headers.Add(header); } ParseMethod(lines[0]); }
private void Parse() { var lines = RequestString.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); if (lines.Length == 0) return; Headers = new List<Header>(); for (int i = 1; i < lines.Length; i++) { Regex headerRegex = new Regex(@"^([a-zA-Z\-]*):\s(.*)$"); var match = headerRegex.Match(lines[i]); Header header = new Header { Name = match.Groups[1].Value, Value = match.Groups[2].Value, }; Headers.Add(header); } ParseMethod(lines[0]); }